本文介绍了我需要在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中转义反斜杠吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!