如何替换"\"在PHP中使用str_replace()? [英] How to replace "\" using str_replace() in PHP?

查看:80
本文介绍了如何替换"\"在PHP中使用str_replace()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除我网站上字符串中的所有反斜杠.我不想使用strip_slashes(),因为我想保持正斜杠.

I would like to remove all back slashes from strings on my site. I do not wish to use strip_slashes(), because I want to keep forward slashes.

这是我正在尝试的代码:

This is the code I am trying:

echo str_replace("\", "", "it\'s Tuesday!");

我想在任何给定的字符串中找到反斜杠并将其删除.但是,此代码无法正常工作.

I want to find the backslash in any given string and remove it. But, this code is not working right.

错误:

syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

我做错了什么?

推荐答案

反斜杠实际上是在字符串中转义右引号.

The backslash is actually escaping the closing quote in your string.

尝试echo str_replace("\\","","it\'s Tuesday!");

这篇关于如何替换"\"在PHP中使用str_replace()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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