Is There RTL Chars


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. /**
  3.  * Is There RTL Chars
  4.  * Check if there RTL characters (Arabic, Persian, Hebrew)
  5.  *
  6.  * @author Khaled Attia (http://twitter.com/khal3d)
  7.  * @param String $string
  8.  * @return bool
  9.  */
  10.  
  11. function is_there_rtl_chars( $string = '' )
  12. {
  13. $rtl_chars_pattern = '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
  14. return preg_match($rtl_chars_pattern, $string);
  15. }
  16.  
  17. // Arabic Or Persian
  18. $string = 'نص عربي أو فارسي';
  19. if( is_there_rtl_chars( $string ) ) {
  20. echo "TRUE\n";
  21. }
  22.  
  23. // Hebrew
  24. $string = 'חופש למען פלסטין';
  25. if( is_there_rtl_chars( $string ) ) {
  26. echo "TRUE\n";
  27. }
  28.  
  29.  
  30. // Latin
  31. $string = 'English';
  32. if( ! is_there_rtl_chars( $string ) ) {
  33. echo "FALSE\n";
  34. }

URL: http://twitter.com/Khal3d/status/52076070178013185

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.