2014-12-03 62 views
3

我有以下變量的內容:PHP preg_match與其他類型的捲曲引號不匹配。如何避免?

$content_content = '「I can’t do it, she said.」';

我想在每一個「字」,包括收縮做的preg_match,所以我使用的preg_match如下:

if (preg_match_all('/([a-zA-Z0-9’]+)/', $content_content, $matches)) 
{ 
    echo '<pre>'; 
    print_r($matches); 
    echo '</pre>'; 
} 

然而,通過在正則表達式中包括'它似乎還包括捲曲雙引號,如上述命令輸出:

Array 
(
    [0] => Array 
     (
      [0] => �� 
      [1] => I 
      [2] => can’t 
      [3] => do 
      [4] => it 
      [5] => she 
      [6] => said 
      [7] => �� 
     ) 

    [1] => Array 
     (
      [0] => �� 
      [1] => I 
      [2] => can’t 
      [3] => do 
      [4] => it 
      [5] => she 
      [6] => said 
      [7] => �� 
     ) 

) 

如何在沒有它的情況下包含「和」?

回答

6

這是因爲在字符集內使用的「花哨」撇號被視爲二進制形式;你需要使用各自modifier啓用Unicode模式:

preg_match_all('/([a-zA-Z0-9’]+)/u', $content_content, $matches) 

Demo

+2

演示,如果需要的話; https://eval.in/229718 – 2014-12-03 05:12:14

+0

@Hanky웃Panky補充,謝謝:) – 2014-12-03 05:13:30