我需要在PHP中转义反斜杠吗? [英] Do I need to escape backslashes in PHP?

查看:58
本文介绍了我需要在PHP中转义反斜杠吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在PHP中转义反斜杠吗?

Do I need to escape backslash in PHP?

echo 'Application\Models\User'; # Prints "Application\Models\User"
echo 'Application\\Models\\User'; # Same output
echo 'Application\Model\'User'; # Gives "Application\Model'User"

所以这是一个转义字符.如果我要引用 Application \ Models \ User ,是否不需要转义( \ )吗?

So it's an escape character. Shouldn't I need to escape it (\) if I want to refer to Application\Models\User?

推荐答案

单引号字符串中仅识别转义序列 \\ \';其他任何 \ 都被解释为纯字符.

In single quoted strings only the escape sequences \\ and \' are recognized; any other occurrence of \ is interpreted as a plain character.

因此,由于 \ M \ U 不是有效的转义序列,因此将按原样对其进行解释.

So since \M and \U are no valid escape sequences, they are interpreted as they are.

这篇关于我需要在PHP中转义反斜杠吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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