将给出的域名转换为小写,并替换成php中文网链接,然后转为json格式

原创 2018-11-19 12:30:06 229
摘要:<?php//已知域名$res = 'HTTP://WWW.BAIDU.COM';$url = strtolower($res);//替换成php.cn$url = str_replace('baidu.com','php.cn',$url);//对url进行编码$new = urlencode($url);$new = urldecode($

<?php

//已知域名

$res = 'HTTP://WWW.BAIDU.COM';
$url = strtolower($res);
//替换成php.cn
$url = str_replace('baidu.com','php.cn',$url);
//对url进行编码
$new = urlencode($url);
$new = urldecode($new);

//查看新链接

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

//根据已知字符串生成url动态字符串

$b = ['p'=>5];

$que = http_build_query($b);

echo $que,'<br>';

//生成新的动态链接

$new .= '?'.$que;

//查看新链接

echo $new,'<br>';

//将新链接转为json格式

$newurl = json_encode($new);

echo $newurl;



批改老师:天蓬老师批改时间:2018-11-19 13:45:31
老师总结:目前json,已经替代了传统的XML格式 ,成为前后端数据交换的主流格式

发布手记

热门词条