how to print xml data with xpath and php if its matches a string pattern?

taylorwarsaw

New Member
I am using php and xpath to display an xml file which is having a xml code like this:\[code\]<?xml version="1.0" encoding="utf-8"?><cities> <city> <city_id>8393</city_id> <country>ITALY</country> <name>Petrosino</name> <establishment_count>1</establishment_count> </city> <city> <city_id>7920</city_id> <country>AUSTRIA</country> <name>Traiskirchen</name> <establishment_count>1</establishment_count> </city></cities>\[/code\]and the php code like this:\[code\]<?php$source = file_get_contents('cities.xml');$xml = new SimpleXMLElement($source);foreach ($xml as $node) { $row = simplexml_load_string($node->asXML()); $result = $row->xpath("//city/name"); if ($result[0]) { $name = $row->name; echo "<div>".$name.", ".$row->country."</div>";} }?>\[/code\]the code is doing fine and printing the result like this:\[code\]Petrosino, ITALYTraiskirchen, AUSTRIA\[/code\]here i dont know how to print the data if its matching the string pattern. Just like if i pass the string "lon" so its display only those city name which are having "lon" string pattern like "london"please help me with this
 
Back
Top