如何使用 PHP 删除转义字符?

发布于 2024-12-09 11:13:44 字数 250 浏览 0 评论 0原文

我有以下文本,

$text = "\\vct=140\\Araignée du soir espoir,araignée du matin,espoir du matin."

我想使用 php 删除转义字符。我不想使用 stripslashes,因为它依赖于服务器。

我想删除 '\vct=140' 之前的 '\' 和 '\ ' 在 '\Arai....' 之前 我怎样才能将它们从字符串中删除?

I have the following text

$text = "\\vct=140\\Araignée du soir espoir,araignée du matin,espoir du matin."

I want to remove the escape characters using php..I do not want to use stripslashes since it is server dependent..

I want to remove the '\' before the '\vct=140' and the '\' before '\Arai....'
How can I remove them from the string?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-12-16 11:13:44

据我所知 stripslashes 可以按照手册工作:

<?php
$string = '\\\\vct=140\\\\Araignée du soir espoir.';
echo $string, "\n";
echo stripslashes($string), "\n";

输出:

\\vct=140\\Araignée du soir espoir.
\vct=140\Araignée du soir espoir.

序列 \\ 位于 特殊字符的转义序列所以你必须逃避斜线两次。

As far as I can tell stripslashes works as per the manual:

<?php
$string = '\\\\vct=140\\\\Araignée du soir espoir.';
echo $string, "\n";
echo stripslashes($string), "\n";

Which outputs:

\\vct=140\\Araignée du soir espoir.
\vct=140\Araignée du soir espoir.

Sequence \\ is in list of escape sequences for special characters so you got to escape slashes twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文