我有以下代码:
<?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>
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"在这个应用程序中,
<p>
标签对我造成了困扰,但是strip_tags绝对拒绝删除它,我无法弄清楚为什么。我实际上放弃了strip_tags,并尝试使用正则表达式 /<(.|\n)*?>/ 进行preg_replace替换:preg_replace('/<(.|\n)*?>/', '', $firstArticle->introtext);
但是那也不起作用!当我输出它时,我该如何从这个字符串中剥离所有HTML标记(匹配或不匹配)?