Posted By

iroybot on 01/28/11


Tagged

php xml XPath


Versions (?)

Using PHP in XPath


 / Published in: PHP
 

I'm using this out of laziness. PHP is slowing things down here, since it's not as close to C as XPath. A better solution would be to have an attribute specifically for search purposes (either in upper or lowercase).

  1. $xpath = new DOMXPath($dom);
  2. if (method_exists($xpath, "registerPHPFunctions")) {
  3. $xpath->registerNamespace("php", "http://php.net/xpath");
  4. $xpath->registerPHPFunctions('strtolower');
  5. $query = "/root/item[contains(@name_es,'$term') or contains(php:functionString('strtolower',@name_es),'$term')]";
  6. } else {
  7. // fallback without PHP
  8. }

Report this snippet  

You need to login to post a comment.