簡體   English   中英

兩個HTML詞組之間的preg_match_all

[英]preg_match_all between two html phrases

我正在嘗試從<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);
?>

沒有顯示...數組([0] =>數組([0] =>

解決了...似乎print_r只是t show anything, i don都沒t show anything, i don知道為什么。 var_dump就像魅力一樣

我可以肯定,由於不平衡的雙引號和正則表達式中的尖括號, 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

看到變化

甚至var_dump的輸出在viper-7中也會受到影響...但是您至少可以看到匹配項。

請注意,如果您執行print_r($match[1]); 你會得到更體面的印刷品:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM