Home >Backend Development >PHP Problem >How to change url in php
How to change the url in php: first use "parse_url()" to parse the url; then take out the desired part; then use "http_build_query()" to build the query string; and finally modify the URL part.
Recommended: "PHP Video Tutorial"
PHP Modify the part with symbols behind the URL
1. Use parse_url() to parse the url and take out the part you want.
2. Use http_build_query() to build the query string, which is the part after the question mark.
<?php $url="xx.php?levelids=level2&id=45"; // 设置了 PHP_URL_PATH,意思是只取 xx.php $path=parse_url($url, PHP_URL_PATH); // 构建查询字符串 $query=http_build_query(array('location'=>'j307')); // 打印出 xx.php?location=j307 echo "$path?$query"; ?>
The above is the detailed content of How to change url in php. For more information, please follow other related articles on the PHP Chinese website!