0

I am parsing html using domxpath in php, and extracting description out of the webpage. But the problem I am facing is that its case sensitive and giving an error if anything is written in different case. here is my code:

$d=new DOMDocument();
$d->loadHTML($source);
$domx = new DOMXPath($d);
$description=$domx->query("//meta[@name='description']")->item(0)->getAttribute('content');

its working fine when everything is in lower case, but gives error if anything is written in any other case. Is there any flag or something which can make domxpath case insensitive.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sourabh
  • 1,757
  • 6
  • 21
  • 43
  • 1
    http://stackoverflow.com/questions/625986/how-can-i-use-xpath-to-perform-a-case-insensitive-search-and-support-non-english – inhan Jul 19 '12 at 19:33
  • that answer is about xml, am pretty new about domxpath and am parsing html data so didn't checked that answer before. – Sourabh Jul 19 '12 at 19:38
  • http://www.php.net/manual/en/domxpath.query.php#77048 This comment implies that using lowercase in your xpath expressions should always work if you used `DOMDocument::loadHTML()`. Did you test this? – Sergey Eremin Jul 19 '12 at 19:41
  • @kgb this comment implies elements and attribute names are case insensitive but 'description' is the value of name attribute of meta element, which is case sensitive. – Sourabh Jul 19 '12 at 19:46

1 Answers1

1

That might be cheating, but would this help?

$d=new DOMDocument();
$d->loadHTML(mb_strtolower($source));

This is going to make all content lowercase too...

Sergey Eremin
  • 10,994
  • 2
  • 38
  • 44
  • innovative solution I should say, but I have to use that extracted description and this solution will change its case, so not really good idea. – Sourabh Jul 19 '12 at 19:37