Remove backslash from string
Discuss coding issues, and scripts related to PHP and MySQL.
-
Marius
- Posts: 107
Remove backslash from string
How can I remove backslashes from string in php?
I tried the following code.
Code: Select all
$str ='abc-\123';
$str = stripcslashes($str);
echo $str; // abc-S
But as you can see, it returns a different result.
I tried this code with simple str_ireplace():
Code: Select all
$str ='abc-\123';
$str = str_ireplace('\', '', $str);
echo $str; // Error
But it returns:
Code: Select all
Parse error: syntax error, unexpected '', $str);
Maybe it's something simple, but, how can I remove the backslash from string in php?
From 'abc-\123' I want to get 'abc-123'.
Admin
You can use str_ireplace() to remove backslash from string in php, but like in the following code (add two backslashes into the removing argument):
Code: Select all
$str ='abc-\123';
$str = str_ireplace('\\', '', $str);
echo $str; // abc-123
Similar Topics
-
Adding string from database into PDF
PHP - MySQL
First post
Hello Coursesweb I have a problem with my php document to convert it to PFD
I cant find out how to get results from $users into the HTML to the PDF...
Last post
Thanks MarPlo I prefer not to ask anything on stackoverflow.com
because I once typed a small i instead of I.
and received many comments about it....
-
Move the string that matches the regex to the end
JavaScript - jQuery - Ajax
First post
I have the following problem to solve it in JavaScript:
- Find the text which is between small brackets and shift that text with the brackets to...
Last post
Try the following code:
function testToEnd(str){
//get matched string
let st = str.match(/ *\( +\) */g)
if(st){
st = st ;
// replace the...
-
How to escape double quote in JSON string
JavaScript - jQuery - Ajax
First post
I am trying to parse a JSON string 'Hello test' containing double quote which already escaped.
JSON.parse('{ x : Hello \ test }')
But I get...
Last post
You just need to escape the backslash \, so it turns into two backslashes \\
let obj = JSON.parse('{ x : Hello \\ test }')
console.log(obj)