Search code examples
phpjsonresponse

replace string of php response


i am having php file like this..

<?php

        define('HOST','localhost');
        define('USER','root');
        define('PASS','123');
        define('DB','123');

        $mysqli = new mysqli(HOST,USER,PASS,DB);
        /* check connection */
        if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
        }       

        $mysqli->query("SET NAMES 'utf8'");
        //$sql="SELECT via,events,doc FROM profile";
                $sql="SELECT via, doc FROM profile";
        $result=$mysqli->query($sql);
        while($e=mysqli_fetch_assoc($result)){
        $output["response"][]=$e;

        //json_encode($output) = str_replace("\/", '/', json_encode($output));/* not working*/
        }   

        echo(json_encode($output)); 
        $mysqli->close();   

        ?>

it is giving response like this.

{"response":[{"via":"19156001882722","doc":"http:\/\/oursite\/propic_uploads\/58.png"},{"via":"sunil holla","doc":"propic_uploads\/Fantasia Painting(29).jpg"}]}

how can i get the above response like this.I mean how to replace the above response with this one.

{"response":[{"via":"19156001882722","doc":"http://oursite/propic_uploads/58.png"},{"via":"sunil holla","doc":"propic_uploads/Fantasia Painting(29).jpg"}]}

can anyone please help me to get this...


Solution

  • Already solved here: json_encode() escaping forward slashes

    You only need to use the JSON_UNESCAPED_SLASHES flag:

    json_encode($str, JSON_UNESCAPED_SLASHES);