I want to read three values of XML in PHP.

Source: Internet
Author: User
I want to read three values of XML in PHP
$url = "Http://www.cailele.com/static/ssc/newlyopenlist.xml";
$doc = new DOMDocument ();
$doc->load ($url); Reading an XML file
$lst = $doc->getelementsbytagname (' Row ');
for ($i =0; $i <2; $i + +) {
$iframe = $lst->item ($i);
$t 1= $iframe->attributes->getnameditem (' expect ')->value;
$t 2= $iframe->attributes->getnameditem (' Opencode ')->value;
$t 3= $iframe->attributes->getnameditem (' opentime ')->value;
$t 1=substr ($t 1,-9);
Kjdata ($t 2,1, $t 1, $t 3);


I want to read the XML Expec,opencode,opentime three values, do not know why the reading is not, ask for answers
------Solution--------------------
$url = "Http://www.cailele.com/static/ssc/newlyopenlist.xml";
$doc = new DOMDocument ();
$doc->loadxml (Curl_get ($url));
$lst = $doc->getelementsbytagname (' Row ');
for ($i =0; $i <2; $i + +) {
$iframe = $lst->item ($i);
$t 1= $iframe->attributes->getnameditem (' expect ')->value;
$t 2= $iframe->attributes->getnameditem (' Opencode ')->value;
$t 3= $iframe->attributes->getnameditem (' opentime ')->value;
$t 1=substr ($t 1,-9);
Kjdata ($t 2,1, $t 1, $t 3);
}

function Kjdata () {
echo Join (', ', Func_get_args ()), Php_eol;
}

function Curl_get ($durl) {
$cookiejar = Realpath (' cookie.txt ');
$t = Parse_url ($durl);
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $durl);
curl_setopt ($ch, curlopt_timeout,5);
curl_setopt ($ch, Curlopt_ssl_verifypeer, 0);
curl_setopt ($ch, curlopt_useragent, $_server[' http_user_agent ');
curl_setopt ($ch, Curlopt_referer, "http://$t [host]/");
curl_setopt ($ch, Curlopt_cookiejar, $cookiejar);
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, curlopt_followlocation, true);
$r = curl_exec ($ch);
Curl_close ($ch);
return $r;
}
5,9,6,4,2, 1, 140421023, 2014-04-21 01:55:30
7,6,4,2,4, 1, 140421022, 2014-04-21 01:50:30
  • Related Article

    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.