[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-04-26
4
Medium Priority
?
362 Views
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='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

0
Comment
Question by:Loganathan Natarajan
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Gk
ID: 35473188
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
 
LVL 2

Expert Comment

by:Gk
ID: 35473201
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
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 1000 total points
ID: 35473217
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
 
LVL 36

Author Closing Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

872 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