...

View Full Version : regular expression replace



kamkam
03-14-2009, 06:19 AM
Hi;
i want to have a result like the follwoing by using regular expression
"锕=錒','锿=鎄','皑=皚','嗳=噯','蔼=藹','霭=靄','爱=愛','嫒=嬡";

but my code give me not right result, could anyone help, thanks
"锕=錒 锿=鎄  皑=皚   嗳=噯  蔼=藹  霭=靄  爱=愛   嫒=嬡";

<?php
$string = "锕=錒 锿=鎄  皑=皚   嗳=噯  蔼=藹  霭=靄  爱=愛   嫒=嬡";
$pattern = '/(\s)+/u';
$replacement = '\',\'';
echo preg_replace($pattern, $replacement, $string);
?>

milanchheda
03-14-2009, 06:23 AM
try this one



<?php
$search="  ";
$replace="','";
$string="锕=錒  锿=鎄  皑=皚  嗳=噯  蔼=藹  霭=靄  爱=愛  嫒=嬡";
echo str_ireplace($search,$replace,$string);
?>

kamkam
03-14-2009, 06:49 AM
Thanks a lot. works



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum