2013-10-22 3 views
-2

나는 웹 서비스에 종사하고있다. "템플릿": 내가 응답 이미지 URL을 보내고 있지만, 잘 format.I오고되지 않는 것은 같은 출력을 필요에 "http : //localhost/restaurant/admin/images2.jpg를"json에서 이미지 URL을 인코딩하는 방법은 무엇입니까?

내 코드

한다
header('Content-Type: application/json'); 
include("admin/common/connection.php"); 
$userId= $_GET['user']; 
if(isset($userId)) 
{ 
$select="select * from menu_template_background where user_id='".$userId."'"; 
$query= mysql_query($select); 
$fetch_row= mysql_fetch_array($query); 
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
$str= strripos($url , "/"); 
$sub=substr($url,$str); 
$replace=str_ireplace($sub,"",$url); 

$template=$replace."/admin/".$fetch_row1['template_url']; 
$fetchmenuDesign= array("template"=>$template); 


echo $menuDesign[]=json_encode($fetchmenuDesign); 

} 

이미지 URL을 치려고 할 때 작동하지 않습니다. 코드에 문제가있는 경우 도움을주세요.

+0

http : // localhost/restaurant/admin/images2.jpg는 이미지에 대해 완벽하게 유효한 URL처럼 보입니다. 당신은 * 어떤 포맷을 기대합니까? – ceejayoz

+0

아니요 "http : \/\/localhost \/restaurant \/admin \ /images2.jpg" – user2907907

+0

http : // localhost/restaurant/admin 출력이 필요합니다. /images2.jpg – user2907907

답변

1

PHP의 json_encode은 기본적으로 슬래시를 이스케이프 처리합니다. This is perfectly valid JSON.

json_encode($stuff, JSON_UNESCAPED_SLASHES)을 수행하여이를 재정의 할 수 있지만 (PHP 5.4 이상) 실제로는 필요하지 않습니다.

관련 문제