Skip to content

All topics  /  PHP

How to String Replace Backslash in PHP?

PHP

Nov 25, 2022

Hi Dev,

This tutorial will give you example of how to string replace backslash in PHP. We will use string replace backslash PHP \\ \ with code examples. you can understand a concept of using PHP replace backslash. step by step explain PHP stripslashes() function.

The stripslashes() function removes backslashes added by the addslashes() function. To add backslash inside array of strings, use json_encode().

Example: 1


index.php

<?php
    echo stripslashes("Who\'s john and  peter?");
?>

Output:

Who's john and  peter?

Example: 2

index.php

<?php
   $value = [
      "ADD", "REMOVE","SELECT","MODIFY"
   ];
   echo json_encode(json_encode($value)) . "
    ";
?>

Output:

"[\"ADD\",\"REMOVE\",\"SELECT\",\"MODIFY\"]"

I hope it could help you...