How do I match and retrieve the EMBED tag from the html source

I have html source contains embed tag and want to retrieve only that, for example the below html source, how can i retrieve embed tag ? i need with preg match ...

 i am trying like this, but does not work,
echo preg_match('<embed.+="(.+?)".+?<\/embed>',$result);
<div class="test">
    
      <embed src='http://www.saynow.com/flash/test.swf' quality="high" FlashVars="itemId=test&autoplay=0&duration=04:05&url=http://my.saynow.com" bgcolor="#ffffff" wmode="opaque" width="320" height="65" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>

    
        </div>

Open in new window

LVL 36
Loganathan NatarajanLAMP DeveloperAsked:
Who is Participating?
 
Marco GasiConnect With a Mentor FreelancerCommented:
You regex doesn't work only because you forgot to add delimiters and because preg_match returns true or false, not a string. Try this:

preg_match('/<embed.+="(.+?)".+?<\/embed>/',$result, $match);
echo $match[0];

Cheers
0
 
GkCommented:
Better you search for the string "<embed" and then the next "src" in it. and then "=" and search for the ' or " . if ' is found search for its matching '. if " is found go for its matching ". this is very easy to debug also.

and download the file thru php.
0
 
GkCommented:
http://php.net/manual/en/function.strpos.php
the src need not be the first attribute. if the string changes to <embed name="" src = "" /> your match may not work properly. even the src may miss in the embed tag by mistake!

0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
great!! works now  i was there. but some syntax error
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.