0

我正在尝试从中减去链接 <a class="link" href="http://www.x.ro/index.php?page=profile&amp;aid=560030" title="Profilul lui

我试过了

<?php
$output2='<a class="link" href="http://www.x.ro/index.php?page=profile&amp;aid=560030" title="Profilul lui';
preg_match_all('#<a\sclass="link"\shref="(.*?)"\stitle="Profilul#i', $output2, $match);
print_r ($match);
?>

没有显示... Array ( [0] => Array ( [0] =>

已解决...似乎 print_r 只是不t show anything, i don知道为什么。var_dump 就像一个魅力

4

1 回答 1

0

我很确定这print_r不起作用,因为正则表达式中的双引号和左尖括号不平衡。我将输入字符串更改为:

<a class="link" href="http://www.x.ro/index.php?page=profile&amp;aid=560030" title="Profilul lui"

[我添加了最后的报价]

和你的正则表达式:

#<a\sclass="link"\shref="(.*?)"\stitle="Profilul lui#i

并注意一点

或者,没有开口尖括号:

#a\sclass="link"\shref="(.*?)"\stitle="Profilul lui#i

看到变化

Evenvar_dump的输出在 viper-7 中受到影响......但您至少可以看到匹配项。

请注意,如果你这样做,print_r($match[1]);你会得到更体面的打印:)

于 2013-10-10T20:09:56.540 回答