使用數據庫顯示的HTML字符的文章:笨character_limiter和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 agenda <a href="http://www.google.com">google page</a>
</div>
使用:character_limiter($按行>的文章,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個文本元素正則表達式。我想知道你是否可以使用類似的東西,但有未定義的標籤。我希望你的幫助
,只需使用character_limiter(用strip_tags($按行>的文章),160); 我不認爲這是人爲錯誤(在這種情況下),你在第一個例子中看到,該文本從超鏈接標籤分離。 – csotelo 2012-04-11 14:57:49
@ user1151980,在你的例子中,你不應該在''之前刪除空格'strip_tags',因爲'strip_tags'只刪除HTML標籤,而不是刪除它們前面的空格。 – Jakub 2012-04-11 15:30:12
奇怪...由於某種原因,這些字符串連接在一起。在wordpress論壇中找到了一個解決方案:preg_replace('/ <[a-zA-Z \ /] [^>] *> /','',$ str);在使用該功能之前。 – csotelo 2012-04-11 15:37:51