#########test1.php###############
<?php
$value["name"] = urlencode("我的姓名");
$value["pass"] = urldecode("pass888");
$value["age"] = 30;
$jsonstr = json_encode($value);
//$url="http://127.0.0.1/view/test2.php?id=100&value=$jsonstr";
$url="http://www.baidu.com";
$html = file_get_contents($url);
echo $html;
?>
#############127.0.0.1/view/test2.php#####################
<?php
$x = json_decode(stripslashes ($_GET["value"]), true);
echo urldecode($x["name"]);
echo urldecode($x["pass"]);
echo urldecode($x["age"]);
?>
本文通过两个PHP脚本示例介绍了如何使用PHP进行URL编码解码,并将数组转换为JSON字符串,再从URL中获取并解析JSON数据。第一个脚本创建了一个包含姓名、密码和年龄的数据数组,并将其转化为JSON格式发送到第二个脚本。第二个脚本则接收该JSON数据,解析后输出。
4964

被折叠的 条评论
为什么被折叠?



