I'm trying to get the content of a certain div from a page and store it in my db. I did the following:
$html = file_get_contents($url);
$dom = new SmartDOMDocument();
$dom->loadHTML($html);
$div_tags = $dom->getElementsByTagName('div');
foreach ($div_tags as $element) {
if(strpos($element->getAttribute('itemprop'), 'description') !== false)
$description = $element->nodeValue;
}
I used SmartDOMDocument because it handles UTF-8 better than DOMDocument
.
Now, this will give me the text of the element
without the tags. I tried this solution and it did give me the text with the tags. However, when I tried to store it in my db, I couldn't!
Is there a better way to get the utf-8 text with the tags
from the element and store it properly in a db?
EDIT: the insert statement is pretty simple:
$q = "INSERT INTO `MyTable`.`content` (`description`) VALUES ('$description')";
$r=mysql_query($q);
var_dump($r);