简体   繁体   English

URL中的特殊字符,用于选择数据库

[英]Special characters in URL for DB selection

I am trying to use special danish characters (æøå) in the URL as GET parameters. 我正在尝试在URL中使用特殊的danish字符(æøå)作为GET参数。 So for instance I have this URL: 例如,我有这个URL:

     http://example.com?name=åge

that URL will get converted into the ASCII equivalent automatically, so in the URL it will read: 该网址将自动转换为ASCII等价物,因此在该网址中显示为:

    http://example.com?name=%E5ge

When i access and print out that value it works just fine, and displays that parameter as: åge 当我访问并打印该值时,它工作正常,并将该参数显示为:

However, i am using that to select stuff in my DB, and this won't work. 但是,我正在使用它来选择数据库中的内容,这将无法正常工作。 If i use the ASCII version in the URL, it won't select anything form the DB and just give me an empty result. 如果我在URL中使用ASCII版本,它将不会从数据库中选择任何内容,只会给我一个空的结果。 If i force the URL to not use ASCII, so it is: http://example.com?name=åge it will work fine when selecting from the DB, but when I display the parameter it shows as this: Ã¥ 如果我强迫的URL不使用ASCII,所以它是: http://example.com?name=åge从数据库中选择时,它会正常工作,但是当我显示参数它显示为这样: Ã¥

I have no idea how to get around this. 我不知道该如何解决。 Any help is appreciated. 任何帮助表示赞赏。

I would transform the parameter to UTF-8 and then prepare the database for a UTF-8 query, with something like this: 我将参数转换为UTF-8,然后为数据库准备UTF-8查询,如下所示:

$name = utf8_encode($_GET['name']);
mysqli_query($mysqli_connector, "SET NAMES UTF8");

And then, prepare your query. 然后,准备您的查询。

That should work. 那应该工作。

I hope that helps! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM