deadliver Posted September 16, 2012 Share Posted September 16, 2012 I am pulling back data from a site using curl. I wanted to simply use dom to some information from the table within. I know the curl is giving the information, but the bit of code to find the tag names and return info is not. Question is this..could this have anything to do with actual php.ini settings? I have not programmed anything php in 7 years so I am head scratching. /** LOAD SETTINGS **/ $url="xxx"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $string = curl_exec($ch); curl_close($ch); // get DOM from URL or file $doc = new DOMDocument(); $doc = str_get_html($string); $elements = $doc->getElementsByTagName('td'); echo $elements->item(0)->nodeValue; The echo fo the td information returns nothing whatsoever. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/ Share on other sites More sharing options...
requinix Posted September 17, 2012 Share Posted September 17, 2012 What's str_get_html()? How about just calling $doc->loadHTML()? Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378494 Share on other sites More sharing options...
deadliver Posted September 17, 2012 Author Share Posted September 17, 2012 sorry it should be loadHTML the str_get_html was from another attempt with an include called Simple Dom written on sourceforge. after loadHTML was not working I tried the other solution as well before posting here. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378498 Share on other sites More sharing options...
requinix Posted September 17, 2012 Share Posted September 17, 2012 So can you post the code you have right now, then? What I assume you have seems right: make sure your php.ini is right for a development environment with error_reporting = -1 display_errors = on and make sure you're getting some sort of error message that we can work with. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378519 Share on other sites More sharing options...
deadliver Posted September 17, 2012 Author Share Posted September 17, 2012 phpinfo() shows the extension is installed, but further investigation shows its not loaded. So...I think thats the issue all around. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378536 Share on other sites More sharing options...
Christian F. Posted September 17, 2012 Share Posted September 17, 2012 You do realize that you're overwriting the DOM object here, right? $doc = str_get_html($string) That is, unless str_get_html () returns a new DOM object, or you're using loadHTML () correctly (which involves more than just replacing the function name). In any case, enable error messages and you'll be told exactly why and where it fails. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378545 Share on other sites More sharing options...
deadliver Posted September 17, 2012 Author Share Posted September 17, 2012 I apologize, I the server is hosted so I can't just open my php.ini etc. I have to wait for answers. Here is what I have found is my issue, and I am not sure why. SCRIPT 1: Works <? $doc = new DOMDocument(); $doc->loadHTML("<table><tr><td>Table Cell1</td></tr><tr><td>Table Cell2</td></tr></table>"); echo $doc->saveHTML(); ?> SCRIPT 2: Fatal error: Call to undefined function loadhtml() in /home/hulldown/public_html/phpsig/test.php on line 12 <? $curlstr = "<table><tr><td>Table Cell1</td></tr><tr><td>Table Cell2</td></tr></table>"; $doc = new DOMDocument(); $doc = loadHTML($curlstr); echo $doc->saveHTML(); ?> The only difference is passing a string variable instead of an actual string to loadHTML(). I feel so stupid because it does not make sense to me what is going on. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378658 Share on other sites More sharing options...
requinix Posted September 17, 2012 Share Posted September 17, 2012 The only difference is passing a string variable instead of an actual string to loadHTML(). No, there's another difference: Fatal error: Call to undefined function loadhtml() in /home/hulldown/public_html/phpsig/test.php on line 12 You're calling loadhtml(). Lowercase. Function names are case-sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378679 Share on other sites More sharing options...
deadliver Posted September 17, 2012 Author Share Posted September 17, 2012 dear Lord I need to pay attention to details. Problem solved. Thanks a lot for the help and patience everyone. Great website and community you have going here. Quote Link to comment https://forums.phpfreaks.com/topic/268449-cannot-seem-to-get-php-dom-working/#findComment-1378700 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.