Web Info and IT Lessons Blog...

Thursday, 11 December 2014

How to remove backslashes in php?

The previous lesson of PHP Lessons Series was about How to add backslashes in php and in this lesson we will learn how to remove backslashes in php.

Remove Backslashes in PHP

stripslashes()

PHP stripslashes() function is used to remove backslashes in front of characters of a string. The basic structure of stripslashes() function is given below:



$str = stripslashes(string);


To remove backslashes from a string, just pass the string in the stripslashes() function. An example use of stripslashes() function is given below:



$str = "My Message is \Hello World!";
$str = stripslashes($str);
echo $str;


The above stripslashes() function will remove the backslash (\) in front of the character 'H' of the string 'My Message is \Hello World!'. The output of the above code is given below:

Output
My Message is Hello World!

Remember stripslashes() function will only remove backslashes (\) from a string not forward slashes (/). Check the example given below:



$str = "My Message is \Hello /World!";
$str = stripslashes($str);
echo $str;


The above stripslashes() function will remove (\) from the string but not (/). The output of above code is given below:

Output
My Message is Hello /World!

stripcslashes()

Just like stripslashes(), stripcslashes() is also used to remove backslashes from a string. The functionality of stripcslashes() is same as stripslashes().

Related Posts
How to add backslashes in php?
Explode and Implode functions in PHP
PHP String Functions
More about PHP String Functions
PHP String Conversion Functions
PHP String Comparison Functions

No comments:

Post a Comment