0

I have HTML output and want to search a specific element on HTML DOM, let say below:

<html>
    <body>
        <div id="post">
            <div>
                <h3><a>Post Title Here</a></h3>
            </div>
        </div>
    </body>
</html>

with that HTML output, from that i wanted to get the text inside tag using preg_match function. How am i going to format it on preg_match?

Answers are greatly appreciated!

PHP Noob
  • 1,597
  • 3
  • 23
  • 34

2 Answers2

1

You should not :) Parse the HTML with a proper HTML parser: less headache, much better handling. See here:

How do you parse and process HTML/XML in PHP?

Community
  • 1
  • 1
Palantir
  • 23,321
  • 9
  • 75
  • 85
0

You can use phpQuery like this:

phpQuery::newDocumentHTML($yourHTML);
$resultData = pq('div#post h3 > a');
echo $resultData; // Post Title Here
Sarfraz
  • 367,681
  • 72
  • 526
  • 573