我有一些小的编码问题.我从这里得到一个json数据字符串(自己尝试):
http://cdn.content.easports.com/fifa/fltOnlineAssets/C74DDF38-0B11-49b0-B199-2E2A11D1CC13/2014/fut/items/web/179899.json
Run Code Online (Sandbox Code Playgroud)
数据中的名称如下所示
Ari Skúlason
Run Code Online (Sandbox Code Playgroud)
如何使用适当的编码获取此数据,以便它的AriSkúlason?
我尝试在php中将它切换为utf-8
echo mb_convert_encoding($r,'ISO-8859-1','utf-8');
Run Code Online (Sandbox Code Playgroud)
让我更接近,但它仍然不对
Ari Sk?lason
Run Code Online (Sandbox Code Playgroud)
我的php curl请求:
$location = 'http://cdn.content.easports.com/fifa/fltOnlineAssets/C74DDF38-0B11-49b0- B199-2E2A11D1CC13/2014/fut/items/web/179899.json';
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json'));
$r = curl_exec($ch);
curl_close($ch);
echo mb_detect_encoding($r);
$r = mb_convert_encoding($r,'ISO-8859-1','utf-8');
print_r($r);
Run Code Online (Sandbox Code Playgroud) 我想用苗条做一个api.它将出现在名为api的目录中的"tools"子域中.
http://tools.fifaguide.com/api
Run Code Online (Sandbox Code Playgroud)
我的.htaccess文件应该是什么样的?
目前我的.htaccess位于我的Wordpress目录(html - > .htaccess),它看起来像这样:
<IfModule mod_rewrite.c>
//my part
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/index.php
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/index.php [L]
//wordpress part
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
这个问题是我尝试的时候
http://tools.fifaguide.com/api/hello/steve
Run Code Online (Sandbox Code Playgroud)
我立即被重定向回api/index.php,而不是留在/ api/hello/steve并显示结果.
似乎wordpress正在实现这一点,但我该如何防止呢?
我想制作我的第一个api,但是我在设置网址时遇到了麻烦.api url在这里:
http://tools.fifaguide.com/api/
Run Code Online (Sandbox Code Playgroud)
例如,如果有人去:
http://tools.fifaguide.com/api/player/messi
Run Code Online (Sandbox Code Playgroud)
然后我需要加载这个页面:
http://tools.fifaguide.com/api/server.php
Run Code Online (Sandbox Code Playgroud)
我在.htaccess写什么?我应该把它放在哪里?
这就是我现在所拥有的:
RewriteEngine On
RewriteRule ^api http://tools.fifaguide.com/api/server.php
Run Code Online (Sandbox Code Playgroud)
但它没有做任何事情,htacces文件也在api文件夹中.任何帮助都会真的很难受!
所以我有这个脚本需要一堆json文件并将它们发送到我的数据库.该脚本适用于8777个文件,但对于70个文件,我得到以下mysql语法错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Shea', '', '190', '1981-4-30', 'Right', '106', '13', '25', '65', '39', '64', '61' at line 1
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的循环,我为长查询道歉:
For($id=1; $id<=205600; $id++)
{
if (file_exists('data/players/'.$id.'.json'))
{
//read json file
$json_file = file_get_contents('data/players/'.$id.'.json');
$file_data = json_decode($json_file, true);
//my super long query
$query = 'INSERT INTO `db`.`table` (`id`, `first_name`, `last_name`, `common_name`, `height`, `dob`, `foot`, `club_id`, `league_id`, `nation_id`, `attribute1`, `attribute2`, …Run Code Online (Sandbox Code Playgroud)