technopup 0 Newbie Poster

Hello,

I have a PHP file that lists a Post Code variable ($thisPostcode). Using simpleXML I need to compare the value of the Post Code variable to the Post Code attribute in an xml document, if there is a match I need it to echo the statement below if not do nothing. It all works fine as long as there is a valid match in the xml file, but if there is no match then I get the following error "Fatal error: Call to a member function attributes() on a non-object... " Any help would be great.

Thanks

$xml = new SimpleXMLElement(file_get_contents('country.xml'));
$postCode = ($country_info_arr[0]['thisPostcode']);
$theInfo = $xml->xpath("/World/country/city[@postcode='$thisPostcode']");
$thePostcode = $theInfo[0]->attributes()->postcode;


if ($country_info_arr[0]['postCode']==$thisPostcode)
{
echo 'This is the postcode'.($thePostcode).'for this area.';

 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.