使用 preg 替换 php 从字符串中删除反斜杠 \ [英] Remove backslash \ from string using preg replace of php
本文介绍了使用 preg 替换 php 从字符串中删除反斜杠 \的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想单独使用 php preg replace 删除反斜杠.
I want to remove the backslash alone using php preg replace.
例如:我有一个字符串看起来像
For example: I have a string looks like
$var = "This is the for \testing and i want to add the # and remove \slash alone from the given string";
如何使用php preg_replace
推荐答案
要使用反斜杠替换,必须在 preg_replace
To use backslash in replacement, it must be doubled (\\\\
PHP string) in preg_replace
echo preg_replace('/\\\\/', '', $var);
这篇关于使用 preg 替换 php 从字符串中删除反斜杠 \的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文