用反斜杠 \ ? 分割文本
我已经搜索了几个小时了。 如何用“\”分隔字符串
我需要将 HORSE\COW 分成两个单词并丢失反斜杠。
I've searched for hours.
How can I separate a string by a "\"
I need to separate HORSE\COW into two words and lose the backslash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将为您提供一个数组,对于
"HORSE\COW"
它将给出$array[0] = "HORSE"
和$array[1] = "牛”。对于
"HORSE\COW\CHICKEN"
,$array[2]
将是"CHICKEN"
由于反斜杠是转义字符,因此它们必须是通过另一个反斜杠转义。
This will give you an array, for
"HORSE\COW"
it will give$array[0] = "HORSE"
and$array[1] = "COW"
. With"HORSE\COW\CHICKEN"
,$array[2]
would be"CHICKEN"
Since backslashes are the escape character, they must be escaped by another backslash.
您可以使用
explode()
并转义字符 (\
)。键盘。
输出
You would use
explode()
and escape the escape character (\
).CodePad.
Output
只需
explode()
即可:使用反斜杠用于转义引号并表示特殊字符:
\n
是一个新行。\t
是制表符。\"
是引号。您必须对其进行转义,否则 PHP 会将其读取为字符串结尾。\'
对于单引号也是如此。\\
是一个反斜杠,因为它用于转义其他内容,所以你必须转义它。Just
explode()
it:A backslash is used for escaping quotes and denoting special characters:
\n
is a new line.\t
is a tab character.\"
is a quotation mark. You have to escape it, or PHP will read it as the end of a string.\'
same goes for a single quote.\\
is a backslash. Since it's used for escaping other things, you have to escape it. Kinda odd.