For example, paging, because some links already have parameters, the original parameters cannot be discarded when appending paging information, so determine whether the link has parameters, and then append paging information as needed.
The method is very simple:
Copy code The code is as follows:
((strpos($url, '?') !== false) ? '&' : '?');
Check whether the link contains ?, if so, such as:
http://www.test.com/index .php?id=id
Add an & directly after the link and then follow the paging information:
http://www.jb51.net/index.php?id=id&page=12
If there are no parameters in the link, such as:
http://www.test.com/index.php
You need to add & and then follow the paging information:
http://www.jb51.net /index.php?page=12
Attached is a more robust checking method:
Copy the code The code is as follows:
$old_url = $_SERVER["REQUEST_URI"];
//Check if the link exists?
$check = strpos($old_url, '?') ;
//If exists?
if($check !== false)
{
//If? There are no parameters after it, such as http://www.yitu.org/index.php ?
if(substr($old_url, $check+1) == '')
{
//Additional parameters can be added 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;
?>
http://www.bkjia.com/PHPjc/321319.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321319.htmlTechArticleFor example, paging, because some links already have parameters, the original parameters cannot be discarded when appending paging information. , so determine whether the link has parameters, and then append as needed...