In php, check whether url links already have parameters. add them? Or & Code

Source: Internet
Author: User
In php, how do we check whether url links have parameters and add them? Or, let's share a function. The code is as follows: Copy the code? Php $ old_u...

In php, how do we check whether url links have parameters and add them? Or &, let's share a function.

The code is as follows:
$ Old_url = $ _ SERVER ["REQUEST_URI"];

// Check whether the link exists?
$ Check = strpos ($ old_url ,'? ');

// If yes?
If ($ check! = False)
{
// If? No parameters, such as hindex. php?
If (substr ($ old_url, $ check + 1) = '')
{
// You can add additional parameters directly.
$ New_url = $ old_url;
}
Else // if there is a parameter, such as index. php? ID = 12
{
$ New_url = $ old_url .'&';
}
}
Else // if it does not exist?
{
$ New_url = $ old_url .'? ';
}

Echo $ new_url;
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.