url json 常用函数

Original 2019-05-04 16:35:39 374
abstract:<?php $url = "http://www.baidu.com"; $url = urlencode("http://www.baidu.com"); echo $url; $url = urldecode($url); echo '<a 
<?php
$url = "http://www.baidu.com";
$url = urlencode("http://www.baidu.com");
echo $url;

$url = urldecode($url);

echo '<a href="'. $url .'">php中文网</a>';

echo "<hr>";

$arr = ['cate_id'=>3,'art_id'=>10];
echo http_build_query($arr);
echo "<hr>";


//json  必须使用utf8编码,不能处理资源类型,resource
$name = '你好';
echo json_encode($name);//字符串

echo "<br>";
echo json_encode($arr);//数组
echo "<br>";
$obj = new stdClass();
$obj->name = "我的";
$obj->age = 30;

echo json_encode($obj);//对象
echo "<br>";
//json_decode()默认返回对象
$json = '{"cate_id":3,"art_id":10}';

$res = json_decode($json);
echo gettype($res),"<br>";

echo "art_id 是 : ",$res->art_id;

?>


Correcting teacher:查无此人Correction time:2019-05-05 09:14:32
Teacher's summary:完成的不错,json数据格式,用作接口,不同的编程语言直接数据交互。继续加油。

Release Notes

Popular Entries