Skip to content

Instantly share code, notes, and snippets.

@itowhid06
Forked from khal3d/is_rtl.php
Created October 25, 2019 05:51
Show Gist options
  • Save itowhid06/d8f52128320cdf0317531dafd9994e37 to your computer and use it in GitHub Desktop.
Save itowhid06/d8f52128320cdf0317531dafd9994e37 to your computer and use it in GitHub Desktop.
Check if there RTL characters (Arabic, Persian, Hebrew)
<?php
/**
* Is RTL
* Check if there RTL characters (Arabic, Persian, Hebrew)
*
* @author Khaled Attia <sourcecode@khal3d.com>
* @param String $string
* @return bool
*/
function is_rtl( $string ) {
$rtl_chars_pattern = '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
return preg_match($rtl_chars_pattern, $string);
}
// Arabic Or Persian
var_dump(is_rtl('نص عربي أو فارسي'));
// Hebrew
var_dump(is_rtl('חופש למען פלסטין'));
// Latin
var_dump(is_rtl('Hello, World!'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment