我正在制作一个自定义RSS提要,需要一种方法来从一个自定义代码中剥离HTML标记,该代码从帖子中获取第一段。
这就是我正在使用的:
<?php
$paragraphAfter = 1; // shows image after paragraph 1
$paragraphsShow = 1; // shows first two paragraphs
$content = apply_filters(\'the_content\', get_the_content());
$content = explode("</p>", $content);
$max = (count($content) < $paragraphsShow) ? count($content) : $paragraphsShow;
for ($i = 0; $i < $max; $i++) {
echo $content[$i] . "</p>";
if ($i == ($paragraphAfter-1)) {
} } ?>
最合适的回答,由SO网友:Gregory Schultz 整理而成
按照马克·卡普伦的建议,我解决了我的问题。真希望有一种喜欢评论的方式。
<?php
$paragraphAfter = 1; // shows image after paragraph 1
$paragraphsShow = 1; // shows first two paragraphs
$content = apply_filters(\'the_content\', get_the_content());
$content = explode(\'</p>\', $content);
$max = (count($content) < $paragraphsShow) ? count($content) : $paragraphsShow;
for ($i = 0; $i < $max; $i++) {
echo **strip_tags($content[$i])** . \'</p>\';
if ($i == ($paragraphAfter-1)) {
} } ?>