note 81486 added to function.preg-replace

From: Date: Fri, 29 Feb 2008 20:02:05 +0000
Subject: note 81486 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-136616@lists.php.net to get a copy of this message
Below is a function for converting Hebrew final characters to their normal equivelants should they appear in the middle of a word. The /b argument does not treat Hebrew letters as part of a word, so I had to work around that limitation. <?php $text="עברית מבולגנת"; function hebrewNotWordEndSwitch ($from, $to, $text) { $text= preg_replace('/'.$from.'([א-ת])/u','$2'.$to.'$1',$text); return $text; } do { $text_before=$text; $text=hebrewNotWordEndSwitch("ך","כ",$text); $text=hebrewNotWordEndSwitch("ם","מ",$text); $text=hebrewNotWordEndSwitch("ן","נ",$text); $text=hebrewNotWordEndSwitch("ף","פ",$text); $text=hebrewNotWordEndSwitch("ץ","צ",$text); } while ( $text_before!=$text ); print $text; // עברית מסודרת! ?> The do-while is necessary for multiple instances of letters, such as "אנני" which would start off as "אןןי". Note that there's still the problem of acronyms with gershiim but that's not a difficult one to solve. The code is in use at http://gibberish.co.il which you can use to translate wrongly-encoded Hebrew, transliterize, and some other Hebrew-related functions. To ensure that there will be no regular characters at the end of a word, just convert all regular characters to their final forms, then run this function. Enjoy! ---- Server IP: 212.199.163.191 Probable Submitter: 192.117.111.61 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/81486 Del: integrated -- https://master.php.net/note/delete/81486/integrated Del: useless -- https://master.php.net/note/delete/81486/useless Del: bad code -- https://master.php.net/note/delete/81486/bad+code Del: spam -- https://master.php.net/note/delete/81486/spam Del: non-english -- https://master.php.net/note/delete/81486/non-english Del: in docs -- https://master.php.net/note/delete/81486/in+docs Del: other reasons-- https://master.php.net/note/delete/81486 Reject -- https://master.php.net/note/reject/81486 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136616) next »