Working with ampersands in $_GET functions

时光怂恿深爱的人放手 提交于 2019-12-20 02:32:37

问题


If I have a URL like asdf.com/index.php?a=0&b=2, then using $_GET for a would be 0 and for b would be 2. However, the term I put into a single $_GET function has an ampersand in it already, like a=Steak&Cheese. Is there a way to make ampersands work without the $_GET variable thinking its job ends when the ampersand shows up (therefore not pulling the entire term)?


回答1:


urlencode() it so & turns into %26.

If you need to make a query string out of some parameters, you can use http_build_query() instead and it will URL encode your parameters for you.

On the receiving end, your $_GET values will be decoded for you by PHP, so the query string a=Steak%26Cheese corresponds to $_GET = array('a' => 'Steak&Cheese').




回答2:


Yes, you must URL Encode before request URL. Read this http://www.w3schools.com/TAGS/ref_urlencode.asp




回答3:


Here is a previous post covering this in jquery AJAX requests, but to summarize you have to encoded the uri. This will convert the ampersand value to a ascii value. Ampersand in GET, PHP



来源:https://stackoverflow.com/questions/5228924/working-with-ampersands-in-get-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!