对于Latin5字符集的preg_match

时间:2011-12-09 18:13:27

标签: php regex preg-match

如何修改这些代码以使我的搜索匹配Latin5字符呢? (当我查询以“ç”开头的单词时,我想得到所有以字母“ç”或“Ç”或“c”或“C”开头的单词)

while (preg_match("/([-]?)\"([^\"]+)\"/i", $a, $regs)) 

另一个代码:

preg_match("/".$pattern."/i", remove_accents($word))) || ($common[$word] == 1)
foreach($words['hilight'] as $change) {
while (preg_match("~[^\>](".$change.")[^\<]~i", " ".$title." ", $regs)) {
  $title = preg_replace("~".$regs[1]."~i", "<b>".$regs[1]."</b>", $title);
}
while (preg_match("~[^\>](".$change.")[^\<]~i", " ".$fulltxt." ", $regs)) { 
  $fulltxt = preg_replace("~".$regs[1]."~i", "<b>".$regs[1]."</b>", $fulltxt);
}
$url2 = $url;
while (preg_match("~[^\>](".$change.")[^\<]~i", $url2, $regs)) {
  $url2 = preg_replace("~".$regs[1]."~i", "<b>".$regs[1]."</b>", $url2);
}
}

1 个答案:

答案 0 :(得分:0)

使用php的 str_replace 功能可能是另一种解决问题的方法

        $string="Put here string containing latin 5 characters";
        $changethis = array("I","ı","İ","ö","Ö","ü","Ü","ç","Ç","ş","Ş","ğ","Ğ"," ","\'","#","$","%","^","&","*","?");
        $tothis = array( "i","i","_i","o","_o","u","_u","c","_c","s","_s","g","_g","","","","","","","","","");
        $newstring = str_replace($changethis, $tothis, "$string");