Home > Backend Development > PHP Tutorial > Check if the url link already has php code for parameters. Add ? or &_PHP Tutorial

Check if the url link already has php code for parameters. Add ? or &_PHP Tutorial

WBOY
Release: 2016-07-21 15:40:38
Original
1104 people have browsed it

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;
?>

www.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...
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