-1

Is it possible to select an HTML tag (not-specified) and its contents, depending on whether or not there is a specific string inside it?

e.g.:

<tagouter>
    <tag> lorem ipsum youtube lorem ipsum</tag> 
    outer text 
    <tag> lorem ipsum youtube lorem ipsum TEXT 2</tag> 
<tagouter>

Expected result:

array(array('youtube','<tag> lorem ipsum youtube lorem ipsum</tag>'),array('youtube',<tag> lorem ipsum youtube lorem ipsum TEXT 2</tag>))

With /(\byoutube\b)/ it will be possible to get the string itself. But how to get the containing tags content?

MPe
  • 430
  • 6
  • 23

1 Answers1

0

Using regular expressions to get content from HTML is not a good idea. See this post:

RegEx match open tags except XHTML self-contained tags

Use an HTML parser instead.

SQLDiver
  • 1,948
  • 2
  • 11
  • 14