• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP function stripslashes() – Un-quotes a quoted string

by admin

The stripslashes() function is used to unquote a string that is quoted by using the addslashes() function. This function was introduced in PHP3. The stripslashes() function is the opposite of addslashes(): it removes one set of \-escapes from a string.

Syntax:

stripslashes(string $string): string

To remove backslashes and convert C-style escape sequences to their literal values:

stripcslashes() 

To add slashes to a string:

addslashes() 

Parameters

Parameter Description
string The string to be unescaped.

Return Values

Returns a string with backslashes stripped off. (\’ becomes ‘ and so on.) Double backslashes (\\) are made into a single backslash (\).

Examples

Example 1:

<?php
$str = “Are you Jack?”; // Outputs: Are you Jack? echo stripslashes($str); ?>

Example 2:

$string = "I'm a lumberjack and I'm okay!";
$a = addslashes($string);
// string is now "I\'m a lumberjack and I\'m okay!"

$b = stripslashes($a);
// string is now "I'm a lumberjack and I'm okay!"

Example 3: Remove slashes from data retrieved from a database

// database connection code omitted for brevity 

$author = 'Sam Clemens'; 
// query a db 
$query = "SELECT quote FROM aphorisms WHERE author like "$author'"; 
$result = mysql_query ($query); 

// write out the results of the query 
if (0 == mysql_num_rows ($result)) {
   die ("Sorry, no witticisms from $author for you today!"); 
} 

while ($temp = mysql_fetch_row ($result)) {
   echo stripslashes ($temp[0]), "\n\n"; 
}

Final Thoughts

stripslashes() removes the backslashes from any escape sequence that it encounters in a string. An escape sequence starts with a backslash and is followed by one or more characters. This function is often used to strip backslashes from data retrieved from a database or to clean up data submitted by an HTML form.

Filed Under: PHP

Some more articles you might also be interested in …

  1. PHP Function str_word_count() – Return information about words used in a string
  2. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  3. PHP addslashes function – Quote string with slashes
  4. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another
  5. htaccess Cheatsheet
  6. PHP function bin2hex – Convert binary data into hexadecimal representation
  7. PHP Function strncasecmp() – Binary safe case-insensitive string comparison of the first n characters
  8. PHP function acos – Arc cosine
  9. PHP function str_repeat() – Repeat a string
  10. PHP function strcasecmp() – Binary safe case-insensitive string comparison

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright