Jump to content

php DOM + line number


Case-Sensitive

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.