Check whether the url link has been added to the php code with parameters? Or & amp;

Source: Internet
Author: User

For example, because some links already have parameters, the original parameters cannot be discarded when page information is appended. Therefore, determine whether the link has parameters and add page information as needed.

The method is simple:
Copy codeThe Code is as follows: (strpos ($ url ,'? ')! = False )? '&':'? ');

Check whether the Link contains? , If any, such:
Http://www.test.com/index.php? Id = id
Then add an & icon directly following the link and follow the page information:
Http://www.jb51.net/index.php? Id = id & page = 12

If there are no parameters in the link, for example:
Http://www.test.com/index.php
Add & and keep up with the page information:
Http://www.jb51.net/index.php? Page = 12

A more robust inspection method is attached:
Copy codeThe Code is as follows:
<? Php
$ Old_url = $ _ SERVER ["REQUEST_URI"];
// Check whether the link exists?
$ Check = strpos ($ old_url ,'? ');
// If yes?
If ($ check! = False)
{
// If? There are no parameters behind, such as http://www.yitu.org/index.php?
If (substr ($ old_url, $ check + 1) = '')
{
// You can add additional parameters 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;
?>

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.