0

Foo Bar

     <div id="c">
       Bar
      </div>

I want find all object in id="a" and out put is

 <div id="a">
   <div id="b">
    Foo
  </div>
   <div id="m">
   Bar
  </div>
 </div>

Geat thanks.

Thoman
  • 742
  • 2
  • 9
  • 20

2 Answers2

1

SimpleHTMLDom is memory consuming solution. It may cause memory leaks. I recommend using DOMDocument and DOMXPath. Then you can fetch all div#a by this way:

$xpath->query('//div[@id = "a"]')
Radek Simko
  • 15,886
  • 17
  • 69
  • 107
0

Seems the community has responded to this before as a bad idea. Looks to be other, better ways. Jquery, HTML parsers, etc.

A search on regex in SO

StackOverflow Thoughts on Regex and HTML

PHP/HTML Regex

Community
  • 1
  • 1
Tommy
  • 39,592
  • 10
  • 90
  • 121