剥离H1标签及其内容

时间:2010-05-04 07:52:49

标签: php

我该如何删除

<h1>and its contents</h1>

来自以下一行

strip_tags(substr($article->content(),0,255)

来自这个完整的代码

<?php $last_articles = $this->children(array('limit'=>5, 'order'=>'page.created_on DESC')); ?>
<?php foreach ($last_articles as $article): ?>
<div class="entry">
  <h3><?php echo $article->link($article->title); ?></h3>
  <?php echo strip_tags(substr($article->content(),0,255).'...', '<p><a>'); ?>
</div>
<?php endforeach; ?>

1 个答案:

答案 0 :(得分:4)

试试这个:

$my_title = preg_replace('/<h1[^>]*>([\s\S]*?)<\/h1[^>]*>/', '', $article->content());

相关资源:

http://sarfraznawaz.wordpress.com/2009/09/08/dreamweaver-tip-search-replace-code-snippets/