Home  >  Article  >  Backend Development  >  php输出数据库中的http地址,格式发生改变,//变为/怎么解决

php输出数据库中的http地址,格式发生改变,//变为/怎么解决

WBOY
WBOYOriginal
2016-06-23 13:38:25914browse

关于这个我知道可以用 str_replace  来将\替换为 '' ,但是这样也会有问题,   如果这条json格式的数据里面有汉字, 汉字的\asd5  就会变成asd5。。  有没有其他方法来解决这个问题?


回复讨论(解决方案)

为什么 / 会 变成 \/ 的,你找到原因了吗?
/ 不是特殊字符,没有 php 函数会对其转义(除了preg_quote)

你可以用str_replace  来将\/替换为 '/' 。。。。 

为什么 / 会 变成 \/ 的,你找到原因了吗?
/ 不是特殊字符,没有 php 函数会对其转义(除了preg_quote)



 不知道什么原因。。  存到数据库里。  取出来就变成这样了。。

你没有做,那是不可能的

你没有做,那是不可能的


	function get_js_array($sql){		$result = @mysql_query($sql) or die(mysql_error());		$arr = array();		while($row = @mysql_fetch_array($result, MYSQL_ASSOC)){			$arr[] = $row;  		}		$js = json_encode($arr);		mysql_free_result($result);		return $js;	}


这是我的执行语句。。不知道是这里出问题了吗?

噢!原来是这样

$js = json_encode($arr, JSON_UNESCAPED_SLASHES);

噢!原来是这样

$js = json_encode($arr, JSON_UNESCAPED_SLASHES);


完美解决。。赞!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn