Add backslashes to the predefined characters in a string in PHP

Description

The following code shows how to add backslashes to the predefined characters in a string.

Example


/*  ww w.j  a v  a2s .  c  o m*/
<?php
    $str = "What's XML?";
    echo $str . " This is not safe in a database query.<br>";
    echo addslashes($str) . " This is safe in a database query.";
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone