以下輸入字符串,圖案和:PHP preg_match_all反向引用
$str1 = 'span class="outline">Iron Man butts heads with Nick Fury and Shield after HYDRA attacks a meeting of the United Nations.</span>
<span class="credit">
Dir: <a href="/name/nm0381817/">Vinton Heuck</a>, <a href="/name/nm1367649/">Ciro Nieli</a>, <a href="/name/nm1367649/">Aditya Parikh</a>'
$pattern='/class="credit">[\s]+?Dir:([,\s]+?<a[\s]+?href="\/name\/nm\d{7}\/">([\/\(\)-:@!%*#=_|?$&;.\w\s]+?)<\/a>)+/um';
preg_match_all($pattern,$str1,$dir);
輸出爲的print_r如下:
Array ([0] => Array ([0] => class="credit"> Dir: <a href="/name/nm0381817/">Vinton Heuck</a>, <a href="/name/nm1367649/">Ciro Nieli</a>, <a href="/name/nm1367649/">Aditya Parikh</a>) [1] => Array ([0] => , <a href="/name/nm1367649/">Aditya Parikh</a>) [2] => Array ([0] => Aditya Parikh))
正如可以看到數組[2]給出阿迪蒂亞Parikh的,我希望能夠迎來Vinton Heuck和Ciro Nieli。但沒有。
任何解決方案?
這裏有關於使用HTML的正則表達式的其他幾個問題:
,導致。閱讀其中的一些內容,看看爲什麼不推薦。 –