准备好的语句将 \ 放在  之前

发布于 2024-10-02 03:02:31 字数 2035 浏览 0 评论 0原文

我使用准备好的语句来解扰 BBcode,但由于某种原因,它在发布时将 \ 放在 ' 之前。我不知道是什么原因导致的,但我确信当我将 BBcode 更改为 html 放入数据库时​​会发生这种情况,代码如下所示:

$text = $membership->remove_HTML($text);


    //convert line breaks to <br /> tags.
      $text = nl2br($text);

      //cleans up by removing white space.
      $text = trim($text);

      //now lets replace things BASIC EDITOR
      $text = preg_replace("/\[b\](.*)\[\/b\]/", "<strong>\\1</strong>", $text);
      $text = preg_replace("/\[i\](.*)\[\/i\]/", "<em>\\1</em>", $text);
      $text = preg_replace("/\[u\](.*)\[\/u\]/", "<span style='text-decoration:underline;'>\\1</span>", $text);
      $text = preg_replace("/\[s\](.*)\[\/s\]/", "<del>\\1</del>", $text);

      $text = preg_replace("/\[url\](.*)\[\/url\]/", "<a target='_blank' href='\\1'>\\1</a>", $text);
      $text = preg_replace("/\[url=(.*)\](.*)\[\/url\]/", "<a target='_blank' rel='\\1' href='\\1'>\\2</a>", $text);

      //now lets replace MORE things EXPANDED EDITOR
      $text = preg_replace("/\[img\](.*)\[\/img\]/", "<img>\\1</img>", $text);
      $text = str_ireplace("[hr]","<hr>", $text);
      $text = preg_replace("/\[justify\](.*)\[\/justify\]/", "<p style='text-align:justify;'>\\1</p>", $text);
      $text = preg_replace("/\[center\](.*)\[\/center\]/", "<p style='text-align:center;'>\\1</p>", $text);
      $text = preg_replace("/\[left\](.*)\[\/left\]/", "<p style='text-align:left;'>\\1</p>", $text);
      $text = preg_replace("/\[right\](.*)\[\/right\]/", "<p style='text-align:right;'>\\1</p>", $text);
      $text = preg_replace("/\[h1\](.*)\[\/h1\]/", "<h4>\\1</h4>", $text);
      $text = preg_replace("/\[h2\](.*)\[\/h2\]/", "<h5>\\1</h5>", $text);
      $text = preg_replace("/\[h3\](.*)\[\/h3\]/", "<h6>\\1</h6>", $text);

      $updatenews = $mysql->add_news($_SESSION['user'][0], $headline, $text, $time);

Im using prepared statements to descramble BBcode but for some reason it puts \ before ' when posting. I dont know what causes it, but Im sure it happens when i change the BBcode to html to be put in the database, the code looks like this:

$text = $membership->remove_HTML($text);


    //convert line breaks to <br /> tags.
      $text = nl2br($text);

      //cleans up by removing white space.
      $text = trim($text);

      //now lets replace things BASIC EDITOR
      $text = preg_replace("/\[b\](.*)\[\/b\]/", "<strong>\\1</strong>", $text);
      $text = preg_replace("/\[i\](.*)\[\/i\]/", "<em>\\1</em>", $text);
      $text = preg_replace("/\[u\](.*)\[\/u\]/", "<span style='text-decoration:underline;'>\\1</span>", $text);
      $text = preg_replace("/\[s\](.*)\[\/s\]/", "<del>\\1</del>", $text);

      $text = preg_replace("/\[url\](.*)\[\/url\]/", "<a target='_blank' href='\\1'>\\1</a>", $text);
      $text = preg_replace("/\[url=(.*)\](.*)\[\/url\]/", "<a target='_blank' rel='\\1' href='\\1'>\\2</a>", $text);

      //now lets replace MORE things EXPANDED EDITOR
      $text = preg_replace("/\[img\](.*)\[\/img\]/", "<img>\\1</img>", $text);
      $text = str_ireplace("[hr]","<hr>", $text);
      $text = preg_replace("/\[justify\](.*)\[\/justify\]/", "<p style='text-align:justify;'>\\1</p>", $text);
      $text = preg_replace("/\[center\](.*)\[\/center\]/", "<p style='text-align:center;'>\\1</p>", $text);
      $text = preg_replace("/\[left\](.*)\[\/left\]/", "<p style='text-align:left;'>\\1</p>", $text);
      $text = preg_replace("/\[right\](.*)\[\/right\]/", "<p style='text-align:right;'>\\1</p>", $text);
      $text = preg_replace("/\[h1\](.*)\[\/h1\]/", "<h4>\\1</h4>", $text);
      $text = preg_replace("/\[h2\](.*)\[\/h2\]/", "<h5>\\1</h5>", $text);
      $text = preg_replace("/\[h3\](.*)\[\/h3\]/", "<h6>\\1</h6>", $text);

      $updatenews = $mysql->add_news($_SESSION['user'][0], $headline, $text, $time);

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

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

发布评论

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

评论(1

柒夜笙歌凉 2024-10-09 03:02:31

最快的检查方法是确保 PHP 的 Magic Quotes 已禁用

如果您不想直接修改 PHP 配置,请在滚动 $text 一系列 preg_replaces().

The quickest thing to check is making sure PHP's Magic Quotes are disabled.

If you don't want to get right into mucking around with your PHP configuration, then check to see if the slashes are present before you roll $text through that series of preg_replaces().

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