Return to Snippet

Revision: 43622
at March 28, 2011 05:35 by khal3d


Updated Code
<?php
/**
 * Is There RTL Chars
 * Check if there RTL characters (Arabic, Persian, Hebrew)
 * 
 * @author	Khaled Attia (http://twitter.com/khal3d)
 * @param	String	$string
 * @return	bool
 */

function is_there_rtl_chars( $string = '' )
{
	$rtl_chars_pattern = '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
	return preg_match($rtl_chars_pattern, $string);
}

// Arabic Or Persian
$string = 'نص عربي أو فارسي';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}

// Hebrew
$string = 'חופש למען פלסטין';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}


// Latin
$string = 'English';
if( ! is_there_rtl_chars( $string ) ) {
	echo "FALSE\n";
}

Revision: 43621
at March 28, 2011 05:28 by khal3d


Updated Code
<?php
/**
 * Is There RTL Chars
 * Check if there RTL characters (Arabic, Persian, Hebrew)
 * 
 * @author	Khaled Attia (http://twitter.com/khal3d)
 * @param	String	$string
 * @return	bool
 */

function is_there_rtl_chars( $string = '' )
{
	$rtl_chars_pattern	= '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
	return preg_match($rtl_chars_pattern, $string);
}

// Arabic Or Persian
$string = 'نص عربي أو فارسي';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}

// Hebrew
$string = 'חופש למען פלסטין';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}


// Latin
$string = 'English';
if( ! is_there_rtl_chars( $string ) ) {
	echo $string . ': ';
}

Revision: 43620
at March 28, 2011 05:27 by khal3d


Updated Code
<?php
/**
 * Is There RTL Chars
 * Check if there RTL characters (Arabic, Persian, Hebrew)
 * 
 * @author	Khaled Attia (http://twitter.com/khal3d)
 * @param	String	$string
 * @return	bool
 */

function is_there_rtl_chars( $string = '' )
{
	$rtl_chars_pattern	= '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
	return preg_match($rtl_chars_pattern, $string);
}

// Arabic Or Persian
$string = 'عربي';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}

// Hebrew
$string = 'חופש למען פלסטין';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}


// Latin
$string = 'English';
if( ! is_there_rtl_chars( $string ) ) {
	echo $string . ': ';
}

Revision: 43619
at March 28, 2011 05:26 by khal3d


Updated Code
<?php
/**
 * Is There RTL Chars
 * Check if there RTL characters (Arabic, Persian, Hebrew)
 * 
 * @author	Khaled Attia (http://twitter.com/khal3d)
 * @param	String	$string
 * @return	bool
 */

function is_there_rtl_chars( $string = '' )
{
	$rtl_chars_pattern	= '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
	return preg_match($rtl_chars_pattern, $string);
}

// Arabic Or Persian
$string = '�ص عرب� ا� �ارس�';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}

// Hebrew
$string = '��פש ��ע� פ�ס���';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}


// Latin
$string = 'English';
if( ! is_there_rtl_chars( $string ) ) {
	echo $string . ': ';
}

Revision: 43618
at March 28, 2011 05:24 by khal3d


Initial Code
<?php
/**
 * Is There RTL Chars
 * Check if there RTL characters (Arabic, Persian, Hebrew)
 * 
 * @author	Khaled Attia (http://twitter.com/khal3d)
 * @param	String	$string
 * @return	bool
 */
function is_there_rtl_chars( $string = '' )
{
	$rtl_chars_pattern	= '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
	return preg_match($rtl_chars_pattern, $string);
}

// Arabic Or Persian
$string = 'نص عربي او فارسي';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}

// Hebrew
$string = 'חופש למען פלסטין';
if( is_there_rtl_chars( $string ) ) {
	echo "TRUE\n";
}


// Latin
$string = 'English';
if( ! is_there_rtl_chars( $string ) ) {
	echo $string . ': ';
}

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

Initial Description

                                

Initial Title
Is There RTL Chars

Initial Tags

                                

Initial Language
PHP