我有下面的代碼:爲什麼strip_tags不能在PHP中工作?
<?php echo strip_tags($firstArticle->introtext); ?>
其中$ firstArticle是一個stdClass的對象:
object(stdClass)[422]
public 'link' => string '/maps101/index.php?option=com_content&view=article&id=57:greenlands-newest-iceberg&catid=11:geography-in-the-news' (length=125)
public 'text' => string 'GREENLAND'S NEWEST ICEBERG' (length=26)
public 'introtext' => string '<p>A giant chunk of ice calved off the Petermann Glacier on
the northwest side of Greenland this summer. At nearly 100 square miles (260
sq. km) in size, four times the size of Manhattan, th' (length=206)
public 'date' =>
object(JDate)[423]
public '_date' => int 1284130800
public '_offset' => int 0
public '_errors' =>
array
empty
你可以看到,$ firstArticle-> introtext指字符串:
「<p>
今年夏天,格陵蘭西北部的彼得曼冰川(Petermann Glacier)產下了一大塊冰塊,面積近100平方英里(260平方公里),是曼哈頓四倍大小的」
<p>
標籤是我在這個應用程序中的一個問題,然而strip_tags絕對拒絕刪除它,我找不到原因。其實,我放棄了用strip_tags並試圖做的preg_replace,而不是用正則表達式/ < | *> /(\ n。):
preg_replace('/<(.|\n)*?>/', '', $firstArticle->introtext);
但是,這並沒有任何工作!輸出時如何從這個字符串去掉所有的HTML標籤(匹配或不匹配)?
你是否確定它不是'&lt; p >'那是在那裏? – Wrikken 2010-09-23 17:25:14
我已經在你的字符串上測試過strip_tags(),它在這裏工作。 – Evert 2010-09-23 17:45:13