RE: [PHP] How to check if $string contains Hebrew characters?

From: Date: Wed, 25 Jun 2008 17:48:41 +0000
Subject: RE: [PHP] How to check if $string contains Hebrew characters?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-275946@lists.php.net to get a copy of this message
The strtr will be better as he's not looking to actually replace the characters. Looping through each character and running strtr will work, but you should run a timer on both the regex and strstr. See which is faster. -----Original Message----- From: M. Sokolewicz [mailto:tularis@php.net] Sent: Wednesday, June 25, 2008 12:46 PM To: Will Fitch Cc: 'Nitsan Bin-Nun'; PHP - General list Subject: Re: [PHP] How to check if $string contains Hebrew characters? or do the same but with strtr() Will Fitch wrote: > If your goal is to eventually convert Hebrew chars to something else, you could just use > str_replace or stri_replace and have each Hebrew char as an array element, replaced by another array > element as a match. > > Example in English: > > > str_replace(array('a','b','c'),array('t','u','v'),$string); > > This will replace all instances of a,b and c with t, u, and v respectively. This removes the > regex resource. > > > -----Original Message----- > From: Nitsan Bin-Nun [mailto:nitsanbn@gmail.com] > Sent: Wednesday, June 25, 2008 10:33 AM > To: php php > Subject: [PHP] How to check if $string contains Hebrew characters? > > Hi, > I have a $string and i want to know if it contains Hebrew characters in it, > I wrote the following: > > >> function containHebrewChars ($string) >> { >> $chars = "אבגדהוזחטיכלמנסעפצקרשת"; // ABC of hebrew chars >> (AlefBet) >> $chars = >> preg_replace("/([\xE0-\xFA])/e","chr(215).chr(ord(\${1})-80)",$chars); >> // >> convert it to UTF8 >> if (preg_match("/[".$chars."]/", $string)) return true; >> return false; >> } >> > > I'm pretty sure there is a better way to do this (regex is overkill), any > ideas? > > Regards, > Nitsan >

« previous php.general (#275946) next »