note 90526 modified in function.simplexml-element-xpath by danbrown

From: Date: Mon, 27 Apr 2009 14:46:14 +0000
Subject: note 90526 modified in function.simplexml-element-xpath by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153835@lists.php.net to get a copy of this message
<?php //OpenAndXpath(Filename, Xpath, Return like a array or string) function OpenAndXpath($FilePath,$XpathQuery,$ArrayOrString) { if (file_exists($FilePath)) { $xml = simplexml_load_file($FilePath); $result = $xml->xpath($XpathQuery); while(list( , $node) = each($result)) { $i++; if($ArrayOrString=="a") { $results[$i]=$node; } if($ArrayOrString=="t") { echo $node."<br/>"; } } if($ArrayOrString=="a") { return $results; } } else { exit('Failed to open '.$FilePath); return false; } } print_r( OpenAndXpath('dokument.xml','//title','a')); ?> --was-- function OpenAndXpath($FilePath,$XpathQuery,$ArrayOrString) { //OpenAndXpath(Filename, Xpath, Return like a array or string) if (file_exists($FilePath)) { $xml = simplexml_load_file($FilePath); $result = $xml->xpath($XpathQuery); while(list( , $node) = each($result)) { $i++; if($ArrayOrString=="a") { $results[$i]=$node; } if($ArrayOrString=="t") { echo $node."<br/>"; } } if($ArrayOrString=="a") { return $results; } } else { exit('Failed to open '.$FilePath); return false; } } print_r( OpenAndXpath('dokument.xml','//title','a')); http://php.net/manual/en/function.simplexml-element-xpath.php

« previous php.notes (#153835) next »