PHP/MySQL - Special characters in URLs. How to avoid?

后端 未结 2 1538
小蘑菇
小蘑菇 2021-01-23 13:45

My database contains information extracted from an external feed. In this raw text feed, the following text is used in place of special characters:

& - &         


        
相关标签:
2条回答
  • 2021-01-23 13:46

    That's because a '&' within a URL starts a new GET variable. The '?' starts your query string with has 2 items in it, 'brand' = "Franklin" and undefined = "Hédgson's".

    Here is a list of URL escape codes that you should use whenever any of those characters appear in your URL (inside a value, of course). So, the '&' needs to be escaped to '%26' when it is put into the string so that the GET will read it properly.

    0 讨论(0)
  • 2021-01-23 14:02

    You should encode the brand=Franklin&Hédgson's before creating the link, if you are generating the link with php use urlencode http://php.net/manual/en/function.urlencode.php

    Then you can use htmlentities to encode the query before sending it off to mysql in a query http://www.php.net/manual/en/function.htmlentities.php

    0 讨论(0)
提交回复
热议问题