小编jay*_*isc的帖子

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>';
 }
Run Code Online (Sandbox Code Playgroud)

但是,似乎通过在正则表达式中包含',它也会捕获卷曲的双引号,如上面的命令输出:

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] => …
Run Code Online (Sandbox Code Playgroud)

php regex unicode

4
推荐指数
1
解决办法
268
查看次数

标签 统计

php ×1

regex ×1

unicode ×1