How to determine whether there are parameters in php

藏色散人
Release: 2023-03-05 17:00:02
Original
3614 people have browsed it

How to determine whether there are parameters in php: first obtain the link through the "$_SERVER["REQUEST_URI"];" method; then determine whether there are parameters in the link through the if statement; and finally output the judgment result through echo.

How to determine whether there are parameters in php

Recommended: "PHP Video Tutorial"

Example: php determines whether the URL has parameters

$old_url = $_SERVER["REQUEST_URI"]; 
//检查链接中是否存在 ? 
$check = strpos($old_url, '?'); 
//如果存在 ? 
if($check !== false) 
{ 
    //如果 ? 后面没有参数,如 http://www.yitu.org/index.php? 
    if(substr($old_url, $check+1) == '') 
    { 
    //可以直接加上附加参数 
    $new_url = $old_url; 
    } 
    //如果有参数,如:http://www.yitu.org/index.php?ID=12 
    else 
    { 
    $new_url = $old_url.'&'; 
    } 
}
//如果不存在 ?  
else 
{ 
    $new_url = $old_url.'?'; 
} 
    echo $new_url;
Copy after login

The above is the detailed content of How to determine whether there are parameters in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!