Case-Sensitive Posted April 5, 2007 Share Posted April 5, 2007 HI guys I was wondering if its possible to get the line number from the html page retrieved using CURL and parsed with the DOM. An example is bobby validator, which looks at your html page and then tells you if you got a problem, including the line it was found on. I was thinking of saving the parsed dom back to a tmp file and then reading it a line at a time, making note of the line. But this is not very efficient. does anyone have any ideas? any help would be great thanks Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 5, 2007 Share Posted April 5, 2007 You don't parse a DOM with php...that's javascript, and xml depending on your use. Anyway, the way it's done is by using the file command...it reads a file into an array separating elements by the newlines...since arrays have keys that are an integer increment by default, it means that the line numbers become the element key + 1. Alternately read the file into a string, then split it on the newline characters...ultimately giving you the same result as using the file command. http://www.php.net/file Quote Link to comment Share on other sites More sharing options...
Case-Sensitive Posted April 5, 2007 Author Share Posted April 5, 2007 Hey cheers I was thinking of that, but since ive been working with php's DOM functions to get the url and then apply a dom to it: $ch = curl_init(); //set options for the curl session curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //fetch the url and store it as a string $site = curl_exec($ch); $connInfo = curl_getinfo($ch); //close the curl session curl_close($ch); $domObj = new DOMDocument(); $domObj -> loadHTML($siteString); I was thinking if there was a function that i didn't know about, that integrated with CURL/DOM cheers, I will try the suggestion! Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 5, 2007 Share Posted April 5, 2007 Ok, I see you are using the XML dom functions that were adapted for html...I wouldn't recommend using these without a compelling reason...the manual lists them as being in CVS only, which means they are not well documented and may not work as expected. Anyway, off hand I don't know how to get the line number. You may try doing a print_r or var_dump on the object to see the full listing of data that it contains. You never know...it may have the line number stored somewhere. Quote Link to comment Share on other sites More sharing options...
Case-Sensitive Posted April 5, 2007 Author Share Posted April 5, 2007 I'm gonna use explode(), if im right this would result in a proper html page when you print each element out from the array. thanks Quote Link to comment 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.