dousui3124 2014-10-22 18:00
浏览 113
已采纳

有没有办法比较西班牙语中的两个字符串,无论PHP中的重音如何?

My question is, given i have the following php code to compare two strings:

   $cadena1='JUAN LÓPEZ YÁÑEZ';
   $cadena2='JUAN LOPEZ YÁÑEZ';

   if($cadena1===$cadena2){
     echo '<p style="color: green;">The strings match!</p>';
   }else{
     echo '<p style="color: red;">The strings do not match. Accent sensitive?</p>';
   }

I notice for example that if I compare LOPEZ and LÓPEZ then the comparison turns to false.

Is there a way or a function already there to compare theses strings regardless of the Spanish accents?

  • 写回答

5条回答 默认 最新

  • doudao1837 2014-10-22 18:06
    关注

    I would replace all accents in your strings before comparing them. You can do that using the following code:

    $replacements = array('Ó'=>'O', 'Á'=>'A', 'Ñ' => 'N'); //Add the remaining Spanish accents. 
    $output = strtr("JUAN LÓPEZ YÁÑEZ",$replacements);
    

    output will now be equal to cadena2.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器