PHP SimpleXML Example

Source: Internet
Author: User

Tag: cal for simple ret fopen tar var time one

$txt= Getremotetext ($url);if(strlen($txt) > 0){    $xml=simplexml_load_string($txt);//Get 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"]. "\" \ r \ n "; $ret. = "var wg_title = \" ".$title[0] ["title"]. "\" \ r \ n "; $ret. = "var wg_keywords = \" ".$keywords[0] ["keywords"]. "\" \ r \ n "; $ret. = "var wg_description = \" ".$description[0] ["description"]. "\" \ r \ n "; $group _info= "\r\nvar Group_info = [\ r \ n]; $district _info= "\r\nvar District_info = [\ r \ n]; foreach($xml->children () as $child)        {            if("gamelist" = =$child-GetName ()) {                //Group Information                foreach($child->children () as $groupChild)                {                    $group _info. = "['".$groupChild["id"]. "‘,‘" .$groupChild["Gamename"]. "'],\r\n"; }            }            Else if("zonelist" = =$child-GetName ()) {                //Partition Information                foreach($child->children () as $districtChild)                {                    $district _info. = "['".$districtChild["id"]. "‘,‘" .$districtChild["ZoneName"]                         . "‘,‘" .$districtChild["StartTime"]. "‘,‘" .$districtChild["GameID"]. "'],\r\n"; }            }        }        $group _info. = "];\r\n"; $district _info. = "];\r\n"; $ret.=$group _info.$district _info; $file=fopen($localJsPath, "W"); fwrite($file,$ret); fclose($file); }}
$xml->xpath ("Webinfo")[0]["logo"] some PHP compiler does not pass

PHP SimpleXML Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.