从字符串中删除所有反斜杠 - php - regex [英] Remove all backslashes from a string - php - regex

查看:29
本文介绍了从字符串中删除所有反斜杠 - php - regex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的字符串是

my string is

$str = '<img src="\"images/hai.jpg\"" alt="" /> Text <img src="\"images/hai.jpg\"" alt="" />';

我想从字符串中删除所有\".

i want to remove all \" from the string.

推荐答案

我认为您不是在寻找正则表达式,而是在寻找 stripslashes($str) 方法.

I think you aren't looking for a regex, but for the stripslashes($str) method.

从评论中,我明白你只会用任何东西替换 \",你应该在这里使用一个简单的 str_replace,正如@Gumbo 所说:>

From the comments, I understand that you will only replace \" with nothing, you should use a simple str_replace here, as @Gumbo said:

$str = ...;
$newStr = str_replace('\"', '', $str);

echo $newStr;

您可以为此使用正则表达式,但 pReg 库并不快,如果您能找到执行相同操作的 str_* 或数组变体,我总是建议使用它而不是 preg_*

You can use regular expressions for this, but the pReg library isn't fast, if you can find a str_* or array variant which does the same I always recommend to use that instead of preg_*

这篇关于从字符串中删除所有反斜杠 - php - regex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆