简体   繁体   English

用PHP编码法语字符

[英]Encoding French characters in PHP

I have an XML document full of "producers": 我有一个充满“生产者”的XML文档:

<producer>
   <name></name>
   <owner></owner>
   <address>
      <civic></civic>
      <mailing/>
      <town></town>
      <province></province>
      <postal></postal>
      <phone></phone>
      <fax></fax>
      <email></email>
      <website/>
   </address>
   <products>
      <product></product>
      <product></product>
      <product></product>
      <product></product>
      <product></product>
      <product></product>
      <product></product>
   </products>
   <exports>
      <region></region>
      <region></region>
      <region></region>
      <region>l'Amérique du Nord</region>
   </exports>
</producer>

For example I want to search for the phrase "l'Amérique du Nord", which is one of the regions for this particular producer: 例如,我要搜索短语“ l'Amériquedu Nord”,这是该特定制作人的区域之一:

$query = "l'Amérique du Nord";
$xml = simplexml_load_file("../business-directory/producers-fr-nb.xml");

$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÂÆÇÈÉÊËÎÏÔŒÙÛÜ"; 
$lower = "abcdefghijklmnopqrstuvwxyzàâæçèéêëîïôœùûü"; 

$nodes = $xml->xpath('//producers/producer[descendant::*[contains(translate(text(), "'.$upper.'", "'.$lower.'"), "'.$query.'")]]');

It didn't work. 没用 I determined the problem to be when I store the phrase "l'Amérique du Nord" in the string $query. 当将短语“ l'Amériquedu Nord”存储在字符串$ query中时,我确定了问题所在。 When I echo $query I get this: l'Amérique du Nord 当我回显$ query时,我得到了:l'Amérique du Nord

I've used functions like htmlspecialchars() and htmlentities() to try encode the é but nothing seems to work. 我已经使用htmlspecialchars()和htmlentities()之类的函数来尝试对é进行编码,但似乎没有任何效果。 Any ideas? 有任何想法吗?

Thanks! 谢谢!

Look ma, I answered :) 妈,我回答了:)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM