There is some text in which some words are wrapped in a combination of characters \ ". For example, Sample text \" Username \ "lorem ipsum. I want to get rid of these nasty \" using a regular expression, but I can’t correctly add them to the pattern. Tried and through the coding of these characters and just write, but nothing comes out, tell me how to choose these characters in a regular expression.
- Please provide an example of code that does not work - tutankhamun
|
2 answers
your string
$str = 'Sample text \"Username\" lorem ipsum';
regular expression so
echo(preg_replace('/\\\"/',"",$str));
or so
echo(preg_replace("/\\\\\"/","",$str));
|
In your case, regulars are not needed. Enough str_replace () function
For example, replace the combination \"
quotes "
$str = 'Sample text \"Username\" lorem ipsum'; $str = str_replace('\"', '"', $str); var_dump($str);
Result
string 'Sample text "Username" lorem ipsum' (length=34)
or completely remove such combination
$str = 'Sample text \"Username\" lorem ipsum'; $str = str_replace('\"', '', $str); var_dump($str);
Result
string 'Sample text Username lorem ipsum' (length=32)
|