douhu2890 2014-10-14 05:38
浏览 34
已采纳

如何在php中匹配e和é

I am retrieving a data from data base in that some of the array contains a result like this.

playa|beach|mar|isco

When the user types e or é.I want to display only "beach".If the user types i or í i want to display only "isco". I am using this code:

$indx=0;
while($row = mysql_fetch_array($rc)){

    if (strpos($row['texto'],'|') !== false) {

        $pieces = explode("|", $row['texto']);
        foreach($pieces as $key => $one) {
           if(strpos($one, $fincas) !== false)
               $indx=$key;
        }
        $row['texto'] = $pieces[$indx];
    }
}

When the user types "e" its displaying properly "beach" but when the user types "é" its displaying "playa".

In php i have to display an array which contains e or é(i or í)

  • 写回答

1条回答 默认 最新

  • dtotuki47568 2014-10-14 06:08
    关注

    First of all, you need to make sure you're getting the POST in a standard format.

    Ensure:

    • in HTTP Header: Content-Type:text/html; charset=UTF-8
    • in HTML Head:
    • in the form tag:

    Then, before starting your loop, translate $fincas into "normalized" ascii:

    iconv("utf-8","ascii//TRANSLIT",$fincas);
    

    That should do it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏