Skip to content

Instantly share code, notes, and snippets.

@marzocchi
Created October 22, 2013 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marzocchi/7098374 to your computer and use it in GitHub Desktop.
Save marzocchi/7098374 to your computer and use it in GitHub Desktop.
find nodes by content in an XML document using XPath
<?php
$doc = new \DomDocument();
$doc->loadXML(file_get_Contents(__DIR__ . '/cities.xml'));
$xp = new \DOMXpath($doc);
echo $xp->query("//return/country[contains(., 'Italy (IT)')]")->length;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment