Home > Backend Development > PHP Tutorial > How to get php parameters with special symbols such as # in the URL

How to get php parameters with special symbols such as # in the URL

小云云
Release: 2023-03-21 15:48:01
Original
4022 people have browsed it

This article mainly introduces to you the solution for PHP to obtain parameters with # and other special symbols in the URL. This article uses the escape function in JS to encode and pass to solve this problem. Friends who need it can refer to it. I hope it can help everyone. .

Today I encountered a front-end using vle.js with a # path. It needs to be transferred to the backend interface to obtain parameters, and then the interface url returns the current page.
The url that the front end will return is escaped today. Function escape
keys = escape(keys); //Encode the string, except * @ - _ + . / these characters
Processing on the php side, use the php get url function to first get the current url path, Convert it back through the rawurldecode function
$aurl = rawurldecode($aurl);
$url = explode('url=',$aurl)[1];
This way you can use the # sign in the url Jumped

Busy first is an example of function usage:

For example, the following PHP code:

<?php
echo $_GET[&#39;key&#39;];
?>
Copy after login

When the url is http://test.com/ When c.php?key=999, the normal output is: 999
When the url is http://test.com/c.php?key=9#888, it can only output: 9
and I want I got 9#888, what should I do? We can only find a way to pass 9#888 to the key.
I solved this problem by encoding and passing the escape function in JS. Friends in need can refer to it.

<input placeholder="输入SN码" type="text" id="searchs" name="searchs" />
<a class=&#39;btn&#39; onclick="searchsn();" href="javascript:;">查询</a>
<script>
    function searchsn() {
        var keys = $(&#39;#searchs&#39;).val();
        if (keys == &#39;&#39;) {
            alert(&#39;请填写SN码&#39;);
            return false;
        }
        keys = escape(keys); //对字符串进行编码,* @ - _ + . / 这几个字符除外
        window.location.href = &#39;c.php?key=&#39; + keys;
    }

</script>
Copy after login

Related recommendations:

Detailed explanation of how to obtain the url instance in php

PHP regular matching code to obtain the domain name in the URL

php Get the file extension in the url

The above is the detailed content of How to get php parameters with special symbols such as # in the URL. 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