Home >Backend Development >PHP Problem >How to replace php url parameters
How to implement php url parameter replacement: first create a PHP sample file; then use the "$_SERVER" method to obtain the passed parameter information; finally, use the "replace_var" method to replace the parameter information.
Recommended: "PHP Tutorial"
PHP Replace the parameters in the url
The code is as follows:
<?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['PHP_SELF']."?"; $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['PHP_SELF']; return $new_url; } ?>
The above is the detailed content of How to replace php url parameters. For more information, please follow other related articles on the PHP Chinese website!