我有一个php文件来检索图像文件名。代码就像这样
<?php
$files = array();
$dir = opendir('upload/');
while ($file = readdir($dir)) {
if ($file == '.' || $file == '..') {
continue;
}
$data = array("picture"=>"http://my IP server/evie/upload/".$file);
$fil[] = $data;
}
header('Content-type: application/json');
$files = array("image"=>$fil);
echo json_encode($files);
?>
当我运行代码时,它看起来像这样
{"image":[{"picture":"http:\/\/my IP server\/evie\/upload\/bangladesh.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/IMG_20130921_074201.jpg"},{"picture":"http:\/\/my IP server\/evie\/upload\/afghanistan.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/india.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/china.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/srilanka.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/nepal.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/skorea.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/Honoka-Miki2-300.jpg"},{"picture":"http:\/\/my IP server\/evie\/upload\/japan.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/nkorea.png"},{"picture":"http:\/\/my IP server\/evie\/upload\/pakistan.png"}]}
它有一个反斜杠'\'。如何更换? 我希望网址看起来像一个有效的网址。有人可以帮帮我吗?
答案 0 :(得分:1)
这里没问题。杰森逃脱斜线。如果你做反向操作--json_decode,你会看到一个斜杠
[0]=>
array(1) {
["picture"]=>
string(44) "http://my IP server/evie/upload/bangladesh.png"
}