现在我有一个数据库。数据库使用全能utf-8排序规则进行编码。实际排序是utf8,我不知道什么编码是。这应该是另一个问题。
Now I got a database. The database is encoded with the almighty utf-8 collation. Actually collation is utf8, I am not sure what the encoding is. That should be another question.
然后我做了一个程序从数据库中检索数据。
Then I made a program to retrieve data from the database.
<?php require_once('convertArraytoJson.php'); require_once('config.php'); mysql_connect ( "localhost", $databaseuser, $databasepassword); mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); @mysql_select_db ($databasename) or die ( "Unable to select database" ); $data=$_GET['id']; $query="SELECT * FROM `tabletes` where id = '".$data."'"; $data = mysql_query($query); while (true){ $info = mysql_fetch_array ( $data, MYSQL_ASSOC ); if ($info == false) { break; } //$output[]=$info; $output[$info['ID']]=$info; unset ($output[$info['ID']]['ID']); } $result = array2json($output); echo $result; ?>数据库的内容如下:
>
通过这样做(你需要放大你的屏幕看到它)调用函数:
Now I call the function by doing this (you need to enlarge your screen to see it):
localhost/domainname/api/test2.php?id=jr-東北本線-荒川橋梁__35.79_139.72它不工作。
但是,如果我不使用$ _GET,但只需直接在代码中输入日语字符即可。
However, if I do NOT use $_GET but simply enter the Japanese characters directly in the code it works.
所以如果我改变:
$data = $_GET['id']至
$data = 'jr-東北本線-荒川橋梁__35.79_139.72'工作正常。
当然,我不想硬编码ID,我想通过$ _GET ['id']访问。我应该怎么办?
Of course, I don't want to hardwire the ID, I want to access that via $_GET['id']. What should I do?
推荐答案只需使用 urlencode()字符串变成:
%E6%9D%B1%E5%8C%97%E6%9C%AC%E7%B7%9A- %E8%8D%92%E5%B7%9D%E6%A9%8B%E6%A2%81 。
检查rfc1738:统一资源定位器(URL)
Check rfc1738: Uniform Resource Locators (URL)
更多推荐
如何使用日语字符管理数据库中的ID
发布评论