1

Hello everybody and thanks for reading. I have a link like this :

<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>

i want to extract only this

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

In other words i want to extract everything after the src=" until the end of the link ". I have been trying with the use of regex but i cant figure out the correct syntax. Some help would be most appreciated.

powtac
  • 40,542
  • 28
  • 115
  • 170
Gunnit
  • 1,064
  • 5
  • 22
  • 45
  • simplexml and xpath //iframe/@src. Try it out and post back if you get stuck with what you've tried. Also, [You can't parse HTML with regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Matt Mar 11 '13 at 16:14
  • not "can't", more like "really really REALLY shouldn't" – Marc B Mar 11 '13 at 16:15

1 Answers1

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]);
powtac
  • 40,542
  • 28
  • 115
  • 170
  • Thanks , i just tried it and it works but i still get a strange output , i get ==> string(325) "$link" how can i get a risult that i can echo $link with no "" – Gunnit Mar 11 '13 at 16:54
  • 1
    Instead of `var_dump()` use `echo $result[1]` or simply `$result[1]` in your code. `var_dump()` shows additional, not required information. – powtac Mar 11 '13 at 16:56