2014-11-24 40 views
0

我使用preg_match我找不到为什么输入文字会变成乱码?如何解决它?preg_match转换输入文字有符号会变成乱码吗?

$输入来自loadHTML我不知道是不是在讨论有关这个问题

$input = $div->nodeValue; 
print_r($input); 

if (preg_match('/([\$€£])/', $input, $matches)) { 
    print_r($matches); 
} 

£25.00 
Array 
(
    [0] => �25.00 
    [1] => � 
    [2] => 25.00 
) 

回答

1

看:preg_match and UTF-8 in PHP

本身,preg_match()不支持Unicode字符串。您必须将u修饰符添加到您的正则表达式中,以告诉pcre引擎将表达式和主题字符串都视为Unicode字符串。

$input = '£25.00'; 
$matches = array(); 

if (preg_match('/([\$€£])/u', $input, $matches)) { 
    print_r($matches); 
} 

打印:

Array 
(
    [0] => £ 
    [1] => £ 
) 
+0

感谢您的描述!! – user1775888 2014-11-25 00:18:54