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文字だけを選択したい、つまり

説明:はじめにには、コンピューターをセットアップするときに実行する必要がある可能性のあるタスクのリストが含まれています。はじめにのタスクには、次のものが含まれます。

タグとこれを達成する方法を除外する必要があります????

4

3 に答える 3

0

タグを削除したいだけの場合は、を使用できますstrip_tags($text);
echo substr(str_replace("&nbsp;","",strip_tags($yourText),0,50))あなたが期待するものを印刷します。

于 2012-10-13T06:01:39.540 に答える
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のどこにでもエコーできます

于 2012-10-13T06:02:14.407 に答える
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エンティティを削除しません。だから私はhtmlの特別な文字を削除する方法から正規表現を借りましたか?

ここで、$final目的の出力が含まれます。

于 2012-10-13T06:05:37.340 に答える