0

使用数据库显示带有 html 字符的文章:

$行->文章:

<div class="article">
As is usual also in Buenos Aires, is held in that city again the official Asterisk Advanced course with the new agenda <a href="http://www.google.com">google page</a>
</div>

使用:character_limiter($row->article, 160) 短文本,但碰巧剪断了超链接,导致html代码出错,我用函数strip_tags()解决...但是显示如下:

<div class="article">
    As is usual also in Buenos Aires, is held in that city again the official Asterisk Advanced course with the new agendagoogle page...
    </div>

如您所见,该函数删除了超链接标签,但也删除了周围的空格。

我读过这篇文章:Problem using strip_tags in php

...但使用设置为 2 个文本元素的正则表达式。我想知道你是否可以使用类似但未定义标签的东西。我希望你的帮助

4

1 回答 1

0

你不应该有你在你的例子中显示的内容,因为你在<a>开始标签和字符串之间有一个空格。您链接到的这个问题只会在您的用户正在添加<div>或类似的情况下表现出来。诸如此类的东西<b><a><u>;当有人打字时会有自然的空间。

您需要执行以下操作:

echo character_limiter(strip_tags($row->article), 160);
  1. 首先剥离标签
  2. 限制字符2。

不要担心奇怪的“空间”问题,如果他们没有在类似的东西之间留出空间,无论如何这将是人为错误的结果the brown fox<a href="#">jumps over</a> the..

HTML 的替代方法是也使用降价代码(您在 SO 上使用什么来输入问题/答案)。它很干净恕我直言。

于 2012-04-11T14:52:24.677 回答