In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
这篇文章主要介绍了php如何替换链接地址,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
php替换链接地址的方法:1、通过"function GetCurUrl(){...}"方法获得当前的脚本网址 ;2、通过"function url_set_value($url,$key,$value) {...}"方法实现链接替换即可。
本文操作环境:windows7系统、PHP7.1版、Dell G3电脑。
php获取当前网址url并替换参数或网址的方法
一是PHP获取当前页面的网址:
代码如下:
//获得当前的脚本网址 function GetCurUrl() { if(!empty($_SERVER["REQUEST_URI"])) { $scriptName = $_SERVER["REQUEST_URI"]; $nowurl = $scriptName; } else { $scriptName = $_SERVER["PHP_SELF"]; if(empty($_SERVER["QUERY_STRING"])) { $nowurl = $scriptName; } else { $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"]; } } return $nowurl; }
另一个是PHP替换网址中query部分的某变量的值比如 ,我们要设$url中的key=321;
其实有几种情况:
$url='www.sina.com/a.php?key=330′;
或$url='www.sina.com/a.php;
或$url='www.sina.com/a.php?cat=2′;
等等。虽然情况很多,但PHP处理起来非常简单,如下:
代码如下:
/* 将URL中的某参数设为某值*/ //【这一段就挺好啊】 function url_set_value($url,$key,$value) { $a=explode('?',$url); $url_f=$a[0]; $query=$a[1]; parse_str($query,$arr); $arr[$key]=$value; return $url_f.'?'.http_build_query($arr); }
不过我的替换是这样写的。。当然也很烂 。。
代码如下:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.