开发者

Making Loop in xPath() : Call to a member function xpath() on a non-object

I want to making loop with xpath() with this function:

function rs(){

$rs = array();
$cities = array("city1", "city2", "city3", "city4", "city5",
    "city6", "city7", "city8");
foreach ($cities as $value) {

    $rs[] = $xmls->xpath("area[city= '$value']");

}
return $rs; }

$rs = rs();

Edit:

function meteor(){

$request_url = "http://meteoroloji.gov.tr/FTPD开发者_如何学JAVAATA/analiz/sonSOA.xml";
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml;}
$xmls = meteor();

with print_r($rs); I have Fatal error: Call to a member function xpath() on a non-object. Is my function wrong? (Im not familliar with OOP) Thanks in advance


$xmls is not in scope, as simple as that. Pass it as an argument (rs($xmls)), or set it as an attribute if this is a method from a class rather then a standalone function (and it if that would be more logical).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜