fork(1) download
  1. <?php
  2.  
  3. $data = '<?xml version="1.0" encoding="utf-8"?>
  4. <cities>
  5. <country name="Абхазия">
  6. <city id="37188" region="27028" head="" type="3" country="Абхазия" part="" resort="" climate="">Новый Афон</city>
  7. <city id="37178" region="10282" head="" type="3" country="Абхазия" part="" resort="" climate="">Пицунда</city>
  8. <city id="37187" region="37187" head="" type="3" country="Абхазия" part="" resort="" climate="">Гудаута</city>
  9. <city id="37172" region="10280" head="" type="3" country="Абхазия" part="" resort="" climate="">Гагра</city>
  10. <city id="37189" region="10281" head="0" type="3" country="Абхазия" part="" resort="0" climate="">Сухум</city>
  11. </country>
  12. </cities>';
  13.  
  14. $xml = new SimpleXMLElement($data);
  15. $search = 'Гагра';
  16. $city = $xml->xpath("//city[text()=\"${search}\"]/@id");
  17. var_dump((int) $city[0]->id);
  18.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
int(37172)