douqilai4263 2017-05-01 15:43
浏览 710

如何输出正斜杠

I have simple problem trying to figure out.

I needs to get output to echo url address like this.

"image": "http://test.info/json/movies/1.jpg"

i'm trying stuck with this code

<?php
include_once 'db_functions.php';
$db = new DB_Functions();
$products = $db->getAllProducts();
$a = array();
$b = array();
$c = 'test.info/json/movies/';
if ($products != false){
    $no_of_users = mysql_num_rows($products);
    while ($row = mysql_fetch_array($products)) {       


        $b["image"] = $c.''.$row["photo"];



        array_push($a,$b);
    }
    echo json_encode($a);
}

?>

Currently i'm getting json output as following.

"image":"http:\/\/test.info\/json\/movies\/uploadsimage0214.png"

please help me to get rid of extra backslashes.

  • 写回答

1条回答 默认 最新

  • duankanjian4642 2017-05-01 16:22
    关注

    You can either use str_replace(); or just just the flag JSON_UNESCAPED_SLASHES as

    echo json_encode($a, JSON_UNESCAPED_SLASHES);
    
    评论

报告相同问题?