Home  >  Article  >  Backend Development  >  How to determine whether there are parameters in php

How to determine whether there are parameters in php

藏色散人
藏色散人Original
2020-09-03 09:21:533666browse

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;

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!

Statement:
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