zoukankan      html  css  js  c++  java
  • php SimpleXML 例子

    $txt = GetRemoteText($url);
    if(strlen($txt) > 0)
    {
        $xml = simplexml_load_string($txt); //获取xml
        if($xml)
        {
            $logo = $xml->xpath("webinfo");
            $title = $xml->xpath("title");
            $keywords = $xml->xpath("keywords");
            $description = $xml->xpath("description");
            
            $ret .= "var WG_Logo = "" . $logo[0]["logo"] . ""
    ";
            $ret .= "var WG_Title = "" . $title[0]["title"] . ""
    ";
            $ret .= "var WG_Keywords = "" . $keywords[0]["keywords"] . ""
    ";
            $ret .= "var WG_Description = "" . $description[0]["description"] . ""
    ";
    
            $group_info = "
    var group_info = [
    ";
            $district_info = "
    var district_info = [
    ";
            foreach ($xml->children() as $child)
            {
                if("gamelist" == $child->getName())
                {
                    //组信息
                    foreach($child->children() as $groupChild)
                    {
                        $group_info .= "['" . $groupChild["id"] . "','" . $groupChild["gamename"] . "'],
    ";
                    }
                }
                else if("zonelist" == $child->getName())
                {
                    //分区信息
                    foreach($child->children() as $districtChild)
                    {
                        $district_info .= "['" . $districtChild["id"] . "','" . $districtChild["zonename"]
                             . "','" . $districtChild["starttime"] . "','" . $districtChild["gameid"]. "'],
    ";
                    }
                }
            }
            $group_info .= "];
    ";
            $district_info .= "];
    ";
            $ret .= $group_info . $district_info;
            
            $file = fopen($localJsPath, "w");
            fwrite($file, $ret);
            fclose($file);
        }
    }
    $xml->xpath("webinfo")[0]["logo"] 有些php编译器通不过

  • 相关阅读:
    Java日期计算之Joda-Time
    JAVABEAN EJB POJO区别
    Android 知识体系学习路线
    Linux学习路线(尚观)
    嵌入式学习课程实战(尚观)
    嵌入式学习课程体系(尚观)
    嵌入式学习路线尚观
    C/C++的培训路线(达内)
    部分C/C++书籍
    基本路线
  • 原文地址:https://www.cnblogs.com/barrysgy/p/6098719.html
Copyright © 2011-2022 走看看