I am taking a few paragraphs from a database and try to seperate the paragraphs into an array with regex and different classes..but nothing works.
I tried to do this:
public function get_first_para(){
$doc = new DOMDocument();
$doc->loadHTML($this->review);
foreach($doc->getElementsByTagName('p') as $paragraph) {
echo $paragraph."<br/><br/><br/>";
}
}
But I get this:
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : p in Entity, line: 9 in C:\Inetpub\vhosts\bestcamdirectory.com\httpdocs\sandbox\model\ReviewContentExtractor.php on line 18
Catchable fatal error: Object of class DOMElement could not be converted to string in C:\Inetpub\vhosts\bestcamdirectory.com\httpdocs\sandbox\model\ReviewContentExtractor.php on line 20
Why do I get the message, Is there an easy way to extract all the paragraphs from a string?
UPDATE:
public function get_first_para(){
$pattern="/<p>(.+?)<\/p>/i";
preg_match_all($pattern,$this->review,$matches,PREG_PATTERN_ORDER);
return $matches;
}
I would prefer the second way..But it doesnt work well too..