在PHP中,我需要转义反斜杠吗? [英] In PHP do i need to escape backslashes?
本文介绍了在PHP中,我需要转义反斜杠吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
echo'Application\Models\User';打印Application\Models\User
echo'Application\\Models\\User';相同的输出
echo'Application\Model\'User';给应用程序\Model'User
所以这是一个转义字符,我不应该逃脱它( \
)如果我想参考 Application\Models\User
?
解决方案
在单引号字符串< a>只有转义序列 \\
和 \'
被识别; \
的任何其他事件都被解释为纯文字。
所以,因为 \\ M
和 \U
不是有效的转义序列,它们被解释为
I think this may be a stupid question, but I am quite confused whether 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
So it's a 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.
So since \M
and \U
are no valid escape sequences, they are interpreted as they are.
这篇关于在PHP中,我需要转义反斜杠吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文