【发布时间】:2013-06-22 15:52:42
【问题描述】:
我正在处理一个 PHP 文件,该文件可以回显价格(由另一个网站的数组给出)转换为某种货币(例如欧元)。
我考虑过使用 in_array 函数来检查从其他网页检索到的价格是否包含货币字符。唯一的问题:即使我使用预定义的数组,它也无法识别该符号。如果我尝试将 $currency 数组更改为 priceclass 给出的实际价格,它将起作用。 提前致谢!
$html=file_get_contents('http://thewebsite');
preg_match_all("thepriceclass", $html, $a);
foreach(end($a) as $key=> $value)
{
print print_r($value, true).'<br>';
$currency = array("€");
$value = str_split($value);
$message = "This listing =/= €";
foreach($value as $letter)
{
if (in_array($letter, $currency))
{
$message = "This listing == €";
break;
}
}
echo $message;
break;
}
【问题讨论】:
-
可能是编码问题。
-
顺便说一句,如果你想在另一个字符串中查找一个字符或字符串,使用
strstr(),你不需要将它拆分成一个数组。 -
例如尝试将编码指定为
unicode。 en.wikipedia.org/wiki/Unicode -
@kevin:你的意思是使用它们的 unicode 值作为数组吗?
-
我以前没有使用过这样的货币符号。但是,我认为这可能会对您有所帮助php.net/manual/en/class.numberformatter.php