Hi I've created a system that adds articles in the database, the user can embed youtube or dailymotion or simple flash into the text area. In the home page, I've inserted a slideshow that slides new feed with image, I've writen a simple condition if t开发者_JS百科hat checks if the text contains an embeded video using:
if (ereg('<object>',$text){}
I just want to insert the video(object element in general) in the slide show in case there's an object in the text. in other words I want to extract what's between <object>
and </object>
thank you
I'm not sure about the slideshow part or if you are also trying to modify the content. But for the extraction part there's two options. You can use a simple-minded regular expression like:
preg_match("#<object[^>]*>(.+?)</object>#ims", $text, $matches);
print $matches[1];
Or a more reliable HTML parser with a readable API like phpQuery or QueryPath:
print qp($text)->find("object")->text();
The latter would also allow you to extract attributes more easily.
精彩评论