I use this code to change each symbol in a string with different symbol:
$test = "უნდა არ არ ყაზახმა ერთი ორსავეს დათვალიერებული. გულის ჩავარდნილი დაეძებდა მათი";
$qart = array("/ა/", "/ბ/", "/გ/", "/დ/", "/ე/", "/ვ/", "/ზ/", "/თ/", "/ი/", "/კ/", "/ლ/", "/მ/", "/ნ/", "/ო/", "/პ/", "/ჟ/", "/რ/", "/ს/", "/ტ/", "/უ/", "/ფ/", "/ქ/", "ღ", "/ყ/", "/შ/", "/ჩ/", "/ც/", "/ძ/", "/წ/", "/ჭ/", "/ხ/", "/ჯ/", "/:ჰ:/");
$eng = array("À","Á","Â", "Ã", "Ä", "Å", "Æ", "È", "É", "Ê", "Ë", "Ì", "Í", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "ã", "ä");
echo preg_replace($qart, $eng, $test);
but I get this error message:
Warning: preg_replace() [function.preg-replace]: No ending delimiter '�' found in ...
Can anyone please help?
Regular expressions are not the ideal solution for single character replacement. Use strtr
:
$pairs = array (
'ა' => 'À',
'ბ' => 'Á',
'გ' => 'Â',
// ...
);
$test = strtr($test, $pairs);
try preg_replace /u modifier if your string is in UTF-8.
The pattern expression for PHP’s PCRE functions require delimiters that separate the pattern from optional modifiers. In your case one of the $qart
values does not have /
as delimiters (i.e. ღ
).
But why do you use regular expressions anyway? I don’t see a need why you don’t use simple string replacement with str_replace
. It can take arrays for the search and replacement too.