PHP replace parameters in url

不言
Release: 2023-03-23 21:36:01
Original
3462 people have browsed it

This article mainly introduces PHP to replace parameters in url, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

<?php
$url=$_SERVER["argv"][0];
$url1=replace_var($url,"page",100);
echo $url1;
                                                                                                                                               
function replace_var($url,$string,$new_value)
{
        while(substr($url,0,1)=="&")
        {
                $url=substr($url,1);
        }
        if($url!="")
        {
                $url_array=explode("&",$url);
                $new_url=$_SERVER[&#39;PHP_SELF&#39;]."?";
                $string_len=strlen($string)+1;
                $i=0;
                while($url_array[$i])
                {
                         if(substr($url_array[$i],0,$string_len)==$string."=")
                         {
                                $url_array[$i]=$string."=".$new_value;
                        }
                        if($i>0) $url_array[$i]="&".$url_array[$i];
                        $new_url=$new_url.$url_array[$i];
                        $i++;
                }
        }
        else $new_url=$_SERVER[&#39;PHP_SELF&#39;];
        return $new_url;
}
?>
Copy after login

Related recommendations:

PHP replace string to implement picture adaptive screen example code

php replace some characters in the string function str_ireplace()



The above is the detailed content of PHP replace parameters in url. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template