2012-10-13 38 views
1

一些內容我有像僅顯示更多的內容

<p> 
<strong><span style="font-family: monospace; white-space: pre-wrap; ">Description:Getting Started contains a list of tasks you might want to perform when you set up your computer. Tasks in Getting Started include: &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Dnescription:Getting Started contains a list of tasks you might want to perform when you set up your computer. Tasks in Getting Started include:</span></strong></p> 

內容現在我只需要選擇50個字符,即只

說明:入門包含您可能需要執行的任務列表當你設置你的電腦。在入門任務包括:

應該排除標籤和  如何實現這一目標????

回答

0

如果你只是想刪除標籤,你可以使用strip_tags($text);
echo substr(str_replace("&nbsp;","",strip_tags($yourText),0,50))將打印您所期望的。

+0

但它沒有去掉  – user1742887

+0

@ user1742887看看我的編輯。 – venkatKA

0

你應該這樣做在PHP如下面的例子

$data = '<b>Description: </b> Getting Started contains a list of tasks you might want to perform when you set up your computer. Tasks in Getting Started include:' 

// remove html tags 
$data = strip_tags($data); 

// remove all &nbsp; 

$data = preg_replace("/\[(.*?)\]\s*(.*?)\s*\[\/(.*?)\]/", "[$1]$2[/$3]", html_entity_decode($data)); 

OR 

$data = trim(str_replace('&nbsp;','',$data)); 

//limit characters 

$data = substr($data,0,50); 
現在

,你可以在你的HTML的任何地方呼應這個數據

+0

但它不會剝去  – user1742887

+0

好的。看到更新的答案 – GBD

0
$tmp = "<p><strong><span style=\"font-family: monospace; 
     white-space: pre-wrap;\">Description:Getting Started contains a list 
     of tasks you might want to perform when you set up your computer. Tasks 
     in Getting Started include: &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; 
     &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 
     Dnescription: Getting Started contains a list of tasks you might want 
     to perform when you set up your computer. Tasks in Getting Started 
     include:</span></strong></p>"; 

$tmp = preg_replace("/&#?[a-z0-9]{2,8};/i","",$tmp); 

$final = substr(strip_tags($tmp),0,50); 

編輯:

如前所述,這並未不要刪除html實體。所以我借用了How to remove html special chars?

現在,$final包含您想要的輸出。