【发布时间】:2015-06-23 10:48:16
【问题描述】:
我正在为 wordpress 编写代码以使用 PHP 分隔段落。目的是将帖子的内容拆分为一个数组并相应地回显它们。
这是我的代码
<?php
$content = "<p>123</p> <p>456</p> <p>789</p>"
$p = explode("</p>", $content);
$i=0;
//echo first 2 elements
foreach ($p as $para) {
echo $para;
array_shift($p); //remove the first element
$i++; //increase the element count by 1
if ($i == 2){ break;} //if element has reach 2 meaning second paragraph, stop loop.
}
echo "<br>Break here<br>";
//echo the rest of the element
foreach ($p as $para) {
echo $para;
}
?>
替换这个
$content = "<p>123</p> <p>456</p> <p>789</p>"
如下
$content = apply_filters( 'the_content', get_the_content() );
$content = str_replace( ']]>', ']]>', $content );
用段落标签检索帖子的内容。
我能够达到我的结果,但我只是担心系统过载等后果。
【问题讨论】: