【发布时间】:2019-08-17 08:40:46
【问题描述】:
我进行了广泛的搜索,但没有找到针对我的问题的提示或解决方案。 问题是我无法用单引号匹配单词。这可能是由服务器、php 或 mysql 设置引起的。 我想知道我是否可以解决这个问题。
我在这里有一个活生生的例子:Fiddle with preg_replace_callback
<?php
$message = "1. test autotest test<br \>2. test auto's test<br \>3.test auto test ";
$message = preg_replace_callback("~( auto(?:'s)? )~si", function ($match)
{ return ' <a href="https://example.com">'.$match[1].'</a> '; }, $message, 1);
echo $message;
// here number 2 is correctly replaced, on my site number 3. Number 2 is not working on my site. I suspect the single quote is the problem on my site. Is there a workaround?
?>
结果:
- 测试自动测试测试
- 测试 auto's 测试
- 测试自动测试
当我在我的网站上实现此代码时,auto's 永远不会匹配。这就是为什么我认为它是由服务器、php 或 mysql 设置引起的。我想知道我是否可以在我的正则表达式中解决这个问题。
【问题讨论】:
标签: php regex pcre preg-replace-callback single-quotes