我正在尝试将以下字符串<a href="\"http://localhost/innovare-kh/wp-content/uploads/2014/07/CouncilTax.pdf\"">CouncilTax</a>
与preg_match_all()
匹配,但我一直收到NULL。我测试了它on this website。这就是我使用函数的方法:
preg_match_all('/(?<=href=\")(.*?\.(.*?))\\/', $description, $out)
其中description是上面的字符串,$ out只是一个空变量。
谢谢, 未婚夫
答案 0 :(得分:0)
你需要连续3个反斜杠:
$description = '<a href="\"http://localhost/innovare-kh/wp-content/uploads/2014/07/CouncilTax.pdf\"">CouncilTax</a>';
preg_match_all('/(?<=href=\")(.*?\.(.*?))\\\/', $description, $out);
print_r($out);
<强>输出:强>
Array
(
[0] => Array
(
[0] => \"http://localhost/innovare-kh/wp-content/uploads/2014/07/CouncilTax.pdf\
)
[1] => Array
(
[0] => \"http://localhost/innovare-kh/wp-content/uploads/2014/07/CouncilTax.pdf
)
[2] => Array
(
[0] => pdf
)
)