For example, because some links already have parameters, the original parameters cannot be discarded when page information is appended. Therefore, determine whether the link has parameters and add page information as needed.
The method is simple:
Copy codeThe Code is as follows: (strpos ($ url ,'? ')! = False )? '&':'? ');
Check whether the Link contains? , If any, such:
Http://www.test.com/index.php? Id = id
Then add an & icon directly following the link and follow the page information:
Http://www.jb51.net/index.php? Id = id & page = 12
If there are no parameters in the link, for example:
Http://www.test.com/index.php
Add & and keep up with the page information:
Http://www.jb51.net/index.php? Page = 12
A more robust inspection method is attached:
Copy codeThe Code is as follows:
<? Php
$ Old_url = $ _ SERVER ["REQUEST_URI"];
// Check whether the link exists?
$ Check = strpos ($ old_url ,'? ');
// If yes?
If ($ check! = False)
{
// If? There are no parameters behind, such as http://www.yitu.org/index.php?
If (substr ($ old_url, $ check + 1) = '')
{
// You can add additional parameters directly.
$ New_url = $ old_url;
}
Else // if there are parameters such as: http://www.yitu.org/index.php? ID = 12
{
$ New_url = $ old_url .'&';
}
}
Else // if it does not exist?
{
$ New_url = $ old_url .'? ';
}
Echo $ new_url;
?>