CodeMama Posted April 15, 2009 Share Posted April 15, 2009 I'm trying to take a paragraph then break it into linebreaks and grab each line separately but it's not working, I can get the paragraph but my lines are not I get the object id #6 or #7 everytime Here's my code // grab all the paragraphs on the page $xpath = new DOMXPath($dom); //$graphs = $xpath->evaluate("/html/body//p"); $graphs=$dom->getElementsByTagName("p"); $lines=$dom->getElementsByTagName("br"); // Set $i =5 because first 5 paragraphs are not inspections for ($i = 5; $i+1 < $graphs->length; $i++) { $paragraph = $graphs->item($i); $text = $dom->saveXML($paragraph); $text = trim($text); /* //my experiment for getting line br for ($b = 1; $b+1 < $lines->length; $b++) {*/ $title = $lines->item($i); $addie= $lines->item($i); Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/ Share on other sites More sharing options...
darkfreaks Posted April 15, 2009 Share Posted April 15, 2009 for one you are missing a close bracket for your loop: <?php // grab all the paragraphs on the page $xpath = new DOMXPath($dom); //$graphs = $xpath->evaluate("/html/body//p"); $graphs=$dom->getElementsByTagName("p"); $lines=$dom->getElementsByTagName("br"); // Set $i =5 because first 5 paragraphs are not inspections for ($i = 5; $i+1 < $graphs->length; $i++) { $paragraph = $graphs->item($i); $text = $dom->saveXML($paragraph); $text = trim($text); /* //my experiment for getting line br for ($b = 1; $b+1 < $lines->length; $b++) {*/ $title = $lines->item($i); $addie= $lines->item($i); } ?> Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-810972 Share on other sites More sharing options...
CodeMama Posted April 15, 2009 Author Share Posted April 15, 2009 Yeah maybe but that isn't the problem I probably just snipped it when I cut and pasted my code. A missing bracket would give me the blank page of horror but that isn't what I'm getting I'm getting a return of the $graph but then the $line var isn't working. Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-810974 Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 Correct me if I'm wrong, but <br/> is actually an empty tag, so there's hardly anything in it... Why don't you rather take your paragraph and explode it on <br/>? Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-810984 Share on other sites More sharing options...
CodeMama Posted April 15, 2009 Author Share Posted April 15, 2009 hey mchi! I think that's it, I was looking at it wrong...thanks I will attempt that tomorrow..but it's nearly closing time (hooray) so no more for me today!! Thanks though!! Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-811002 Share on other sites More sharing options...
darkfreaks Posted April 15, 2009 Share Posted April 15, 2009 i agree with the above i just got home but i get this in PHP Tester Uncaught DOM exception dom xpath construct expects parameter 1 to be DOMdocument Null given on line 3 Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-811011 Share on other sites More sharing options...
darkfreaks Posted April 15, 2009 Share Posted April 15, 2009 tidied up the PHP DOM code for ya also i have a feeling the problem lays where you define $dom. can you paste that part? because it is not defined there. ??? <?php // grab all the paragraphs on the page $xpath = new DOMXPath($dom); //$graphs = $xpath->evaluate("/html/body//p"); $graphs=$dom->get_elements_by_tagname("p"); $lines=$dom->get_elements_by_tagname("br"); // Set $i =5 because first 5 paragraphs are not inspections for ($i = 5; $i+1 < $graphs->length; $i++) { $paragraph = $graphs ->item($i); $text = $dom->saveXML($paragraph); $text = trim($text); /* //my experiment for getting line br for ($b = 1; $b+1 < $lines->length; $b++) {*/ $title = $lines->item($i); $addie= $lines->item($i); }?> Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-811029 Share on other sites More sharing options...
darkfreaks Posted April 15, 2009 Share Posted April 15, 2009 Gives me no errors just a blank page: <?php //create a new DOM Document $dom = new domDocument; // grab all the paragraphs on the page $xpath = new DOMXPath($dom); //$graphs = $xpath->evaluate("/html/body//p"); $graphs=$dom->getElementsByTagName('p'); $lines=$dom->getElementsByTagName('br'); // Set $i =5 because first 5 paragraphs are not inspections for ($i = 5; $i+1 < $graphs->length; $i++) { $paragraph = $graphs ->item($i); $text = $dom->saveXML($paragraph); $text = trim($text); /* //my experiment for getting line br for ($b = 1; $b+1 < $lines->length; $b++) {*/ $title = $lines->item($i); $addie= $lines->item($i); }?> Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-811038 Share on other sites More sharing options...
premiso Posted April 16, 2009 Share Posted April 16, 2009 You are not echoing/printing anything else. It is suppose to not show anything due to that fact. Link to comment https://forums.phpfreaks.com/topic/154258-help-with-syntax-on-statement-parsing-woes/#findComment-811085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.