Search code examples
phpstringstripslashes

PHP - Slashes are coming after using the stripshales for String


i am using mysqli connection.

 $conn = new mysqli($host, $user, $password, $database);

Storing the Data in DB with below syntax

$site_description = $conn->real_escape_string($_POST['site_description']);  
$conn->query("UPDATE `r_site_details` SET  `site_description` = '".$site_description."' WHERE `id` = ".$id);
input : Telangana's

it adding slashes. But when i output the value with stripslashes its still showing the slashes in the string

$query = $conn->query("select * from r_site_details where id=$id")or die(mysqli_error());
$result = $query->fetch_assoc();
    echo stripslashes($result["site_description"]) // output : Telangana\'s

Solution

  • Dont Find a Optimize Solution, Just Tried to Replace the Slashes it works fine,

    echo str_replace('\"', '"',str_replace("\'", "'", $result["site_description"]));

    Can anyone suggest me an alternative Solution.