seyedrezabazyar Posted May 7, 2022 Share Posted May 7, 2022 I have two codes at the bottom. The first code is a scraper file that captures and displays the contents of a web page from the "div" tag. index code: function curlGet($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_URL, $url); $results = curl_exec($ch); curl_close($ch); return $results; } function returnXPathObj($item) { $xmlPageDom = new DomDocument(); @$xmlPageDom->loadHTML($item); $xmlPageXPath = new DOMXPath($xmlPageDom); return $xmlPageXPath; } echo returnXPathObj(curlGet('http://localhost/test/page'))->query('//div')->item(0)->nodeValue; // This URL refers to a page that contains the following code The second code is the contents of that web page webpage code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div class="content"> <h1>phpfreaks</h1> <p>www.phpfreaks.com</p> </div> <span class="content2"> <h1>phpfreaks</h1> <p>www.phpfreaks.com</p> </spans> </body> </html> Now when I run the code, it only shows the text and hides the HTML tags. How can I display the contents of the Dave tag along with all the HTML tags? for example: Now displays as follows: phpfreaks www.phpfreaks.com I want to show the following: <h1>phpfreaks</h1> <p>www.phpfreaks.com</p> Quote Link to comment https://forums.phpfreaks.com/topic/314768-problem-retrieving-html-tags-from-domxpath/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.