2011-03-05 4 views

답변

2

가장 좋은 건 strip_tags()을 사용하여 HTML을 제거하고 substr을 사용하여 처음 300 자 정도의 문자 만 표시하는 것입니다. 그렇지 않으면 HTML을 파싱하여 나머지 레이아웃을 손상시키지 않도록 적절한 장소에서 HTML을 파싱해야합니다.

2

strip_tags() 및단어 잘림()

<?php 
$blog_entry = '<div class="myclass"><p><h1>I am trying to write a blog system.</h1> The main page is consist of part of the content of blog entries.</p>  
<p>The problem is how could I make sure the excerpt is truncated correctly, since the blog entries is stored in HTML code.</p> 
<p>Thanks.</p></div>'; 

// Allow a couple of tags (<p>,<a>), or don't - wrap excerpts into your own CSS class in your UI 

$thisExcerpt = wordwrap(strip_tags($blog_entry, '<p>,<a>'),50); 
$thisExcerpt = explode("\n", $thisExcerpt); 
$thisExcerpt = $thisExcerpt[0]; 

echo $thisExcerpt . '...'; 
?> 

출력 :

I am trying to write a blog system. The main... 
관련 문제