Here is my code below.
$dom = new DOMDocument();
$dom->loadHTML($source); // Html String
$xpath = new DOMXPath($dom);
$meta_keywords = $xpath->query("//meta[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'keywords']");
try
{
if($meta_keywords != null)
{
$keyword = $meta_keywords->item(0)->getAttribute("content");
}
}catch (Exception $e) {
echo $e->getMessage();
}
Sometimes it works sometimes it doesn’t. And when it doesn’t work it causes my script to exit without errors warnings and without exceptions.
I decided to use TIDY for my HTML strings.