2013-09-24 59 views
0

我試圖從 <a class="link" href="http://www.x.ro/index.php?page=profile&amp;aid=560030" title="Profilul luipreg_match_all之間的兩個

。減去鏈路我試圖

<?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] = >

解決......好像只是沒t show anything, i don的print_r知道爲什麼。的var_dump工作就像一個魅力

+2

嘗試'的var_dump()'來代替(** **總是用它進行調試,而不是'echo'或'print_r') – zerkms

+0

有效。謝謝。我不知道爲什麼print_r沒有工作... – user2761358

+1

既然這個問題現在已經解決了,有人可以寫一個答案並將其標記爲已解決嗎? –

回答

0

我PRET ty確定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 

同時注意thisthis

,或在不開尖括號:

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

See the change

即使var_dump的輸出受到影響的毒蛇 - 7 ...但你至少可以看到比賽。

請注意,如果你這樣做print_r($match[1]);你得到一個更體面的打印:)