小编Fel*_*ard的帖子

正则表达式也匹配重音字符

我有以下 PHP 代码:

\n\n
$search = "foo bar que";\n$search_string = str_replace(" ", "|", $search);\n\n$text = "This is my foo text with qu\xc3\xa9 and other accented characters.";\n$text = preg_replace("/$search_string/i", "<b>$0</b>", $text);\n\necho $text;\n
Run Code Online (Sandbox Code Playgroud)\n\n

显然,“que”与“qu\xc3\xa9”不匹配。我怎样才能改变这一点?有没有办法让preg_replace忽略所有口音?

\n\n

必须匹配的字符(西班牙语):

\n\n
\xc3\xa1,\xc3\x81,\xc3\xa9,\xc3\x89,\xc3\xad,\xc3\x8d,\xc3\xb3,\xc3\x93,\xc3\xba,\xc3\x9a,\xc3\xb1,\xc3\x91\n
Run Code Online (Sandbox Code Playgroud)\n\n

我不想在应用正则表达式之前替换所有重音字符,因为文本中的字符应该保持不变:

\n\n

“这是我的foo文本,带有qu\xc3\xa9和其他重音字符。”

\n\n

并不是

\n\n

“这是我的foo文本,带有que和其他重音字符。”

\n

php regex character non-ascii-characters accent-insensitive

5
推荐指数
1
解决办法
1575
查看次数

PHP:在多维数组中计算相同的值

我想在多维数组的最深/最后一级计算相同的值:

Array
(
[svote001] => Array
    (
        [0] => 006
        [1] => 006
        [2] => 007
    )

[svote002] => Array
    (
        [0] => 000
        [1] => 000
        [2] => 000
    )

[svote003] => Array
    (
        [0] => 002
        [1] => 003
        [2] => 001
    )
)
Run Code Online (Sandbox Code Playgroud)

转换成

Array
(
[svote001] => Array
    (
        [006] => 2
        [007] => 1
    )

[svote002] => Array
    (
        [000] => 3
    )

[svote003] => Array
    (
        [001] => 1
        [002] => 1
        [003] => …
Run Code Online (Sandbox Code Playgroud)

php arrays multidimensional-array

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