如果文本中有“é”,则在获取字符串比较以在 PHP 中工作时遇到问题。下面是我有一堆调试内联代码的代码。问题是,如果我在下拉列表中选择蒙特利尔,则if
测试不起作用。
if ($metabox->get_the_value() == $key) echo $selected;
// original code pre debug
代码
a= Array(
[INFORMATION] => INFORMATIONS
[LODGING] => HEBERGEMENT
[LOOK OUT FOR] => À SURVEILLER
[Montréal] => Montréal
[PROMOTIONS] ==> PROMOTIONS
[SECTION NAME] ==> NOM DE SECTION
[SPOTLIGHT] ==> EN VEDETTE
)
foreach (a as $key => $val){
echo '<option value="'.$key.'"';
if (strcasecmp ( trim($metabox->get_the_value())), trim($key))== 0) echo $selected ;
echo '>'.$key.' ('.$val.'):'. strcmp ( $metabox->get_the_value(), $key). '</option>';
}
如果我选择并保存蒙特利尔,输出看起来像这样,它被保存在数据库中。
<select name="_content_language_meta[_content_cat_type]">
<option value="-1">Select</option>
<option value="INFORMATION">INFORMATION (INFORMATIONS):Montréal - 1</option>
<option value="LODGING">LODGING (HEBERGEMENT):Montréal - 1</option>
<option value="LOOK OUT FOR">LOOK OUT FOR (À SURVEILLER):Montréal - 1</option>
<option value="Montréal">Montréal (Montréal):Montréal - -1</option>
<option value="PROMOTIONS">PROMOTIONS (PROMOTIONS):Montréal - -1</option>
<option value="SECTION NAME">SECTION NAME (NOM DE SECTION):Montréal - -1</option>
<option value="SPOTLIGHT">SPOTLIGHT (EN VEDETTE):Montréal - -1</option>
</select>
如果选择了 INFORMATION,则输出
<select name="_content_language_meta[_content_cat_type]">
<option value="-1">Select</option>
<option value="INFORMATION" selected="selected">INFORMATION (INFORMATIONS):INFORMATION - 0</option>
<option value="LODGING">LODGING (HEBERGEMENT):INFORMATION - -1</option>
<option value="LOOK OUT FOR">LOOK OUT FOR (À SURVEILLER):INFORMATION - -1</option>
<option value="Montréal">Montréal (Montréal):INFORMATION - -1</option>
<option value="PROMOTIONS">PROMOTIONS (PROMOTIONS):INFORMATION - -1</option>
<option value="SECTION NAME">SECTION NAME (NOM DE SECTION):INFORMATION - -1</option>
<option value="SPOTLIGHT">SPOTLIGHT (EN VEDETTE):INFORMATION - -1</option>
</select>
这是一个 WordPress / MYSQL 网站。想法?