1

大家好,感谢阅读。我有一个这样的链接:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=monte+rosa&amp;aq=&amp;sll=45.454082,9.213138&amp;sspn=0.009016,0.01929&amp;t=h&amp;gl=it&amp;ie=UTF8&amp;hq=&amp;hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&amp;ll=45.690627,8.824349&amp;spn=0.008978,0.01929&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="https://maps.google.it/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=monte+rosa&amp;aq=&amp;sll=45.454082,9.213138&amp;sspn=0.009016,0.01929&amp;t=h&amp;gl=it&amp;ie=UTF8&amp;hq=&amp;hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&amp;ll=45.690627,8.824349&amp;spn=0.008978,0.01929&amp;z=14&amp;iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small>

我只想提取这个

https://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=monte+rosa&amp;aq=&amp;sll=45.454082,9.213138&amp;sspn=0.009016,0.01929&amp;t=h&amp;gl=it&amp;ie=UTF8&amp;hq=&amp;hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&amp;ll=45.690627,8.824349&amp;spn=0.008978,0.01929&amp;z=14&amp;iwloc=A&amp;output=embed

换句话说,我想提取 src=" 之后的所有内容,直到链接结束"。我一直在尝试使用正则表达式,但我无法弄清楚正确的语法。一些帮助将不胜感激。

4

1 回答 1

3
$html = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=monte+rosa&amp;aq=&amp;sll=45.454082,9.213138&amp;sspn=0.009016,0.01929&amp;t=h&amp;gl=it&amp;ie=UTF8&amp;hq=&amp;hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&amp;ll=45.690627,8.824349&amp;spn=0.008978,0.01929&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="https://maps.google.it/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=monte+rosa&amp;aq=&amp;sll=45.454082,9.213138&amp;sspn=0.009016,0.01929&amp;t=h&amp;gl=it&amp;ie=UTF8&amp;hq=&amp;hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&amp;ll=45.690627,8.824349&amp;spn=0.008978,0.01929&amp;z=14&amp;iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
preg_match('~iframe.*src="([^"]*)"~', $html, $result);
var_dump($result[1]);
于 2013-03-11T16:16:37.587 回答