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

Posted on 2011-04-26
Last Modified: 2012-05-11
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='' quality="high" FlashVars="itemId=test&autoplay=0&duration=04:05&url=" bgcolor="#ffffff" wmode="opaque" width="320" height="65" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage=""></embed>


Open in new window

Question by:Loganathan Natarajan
    LVL 2

    Expert Comment

    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.
    LVL 2

    Expert Comment

    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!

    LVL 30

    Accepted Solution

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

    LVL 36

    Author Closing Comment

    by:Loganathan Natarajan
    great!! works now  i was there. but some syntax error

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now