PHP's Network programming

Source: Internet
Author: User

GET:

$htmlsource =file_get_contents ("Http://192.168.0.13/s/interface/shangpin/shangpinDL");
$postArray = Iconv ("Utf-8", "GBK", $htmlsource);
$postArray = Iconv ("GBK", "Utf-8", $postArray);
Echo $postArray;
$de _json = Json_decode ($postArray, TRUE);
echo $de _json;
Echo var_dump ($de _json);

$count _json = count ($de _json);
echo $count _json;
for ($i = 0; $i < $count _json; $i + +)
{
Echo var_dump ($de _json);
$dt _id = $de _json[$i] [' id '];
$dt _pname = $de _json[$i] [' pname '];
echo $dt _id. " >>>> ". $dt _pname;
}

JSON parsing
$postArray = ' [{' data ': {' hello ': ' World '}, ' type ': ' 1234 ', ' Date ': ' 2012-10-30 17:6:9 ', ' user ': ' 000000000000000 ', ' time_ Stamp ": 1351587969902}, {" Data ": {" Hello ":" World "}," type ":" 1234 "," date ":" 2012-10-30 17:12:53 "," User ":" 000000000000000 "," Time_stamp ": 1351588373519}] ';

$de _json = Json_decode ($postArray, TRUE);
$count _json = count ($de _json);

echo $count _json;

for ($i = 0; $i < $count _json; $i + +)
{


$dt _record = $de _json[$i] [' Date '];
$data _type = $de _json[$i] [' type '];
$imei = $de _json[$i] [' User '];
$message = Json_encode ($de _json[$i] [' data ']);

echo $data _type. " >>>> ". $imei." <br/> ";

}

Post:curl

Dump (Ppost ("Http://localhost:8080/thinkox/index.php?s=/home/user/login", $shuzu));//This is the call statement $shuzu is the argument

function Ppost ($url, $arr) {
$post _data = $arr;
$url = $url;
$o = "";
foreach ($post _data as $k = $v)
{
$o. = "$k =". UrlEncode ($v). " & ";
}
$post _data=substr ($o, 0,-1);
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer,1);//This is also the setting for whether to receive the return value
To support cookies
curl_setopt ($ch, Curlopt_cookiejar, ' cookie.txt ');
curl_setopt ($ch, Curlopt_postfields, $post _data);
$result = curl_exec ($ch);
return $result;
}

PHP Network programming

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.