Home >Backend Development >PHP Problem >How to change url in php

How to change url in php

藏色散人
藏色散人Original
2020-09-01 09:29:232768browse

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.

How to change url in php

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(&#39;location&#39;=>&#39;j307&#39;));
// 打印出 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn