通过 substr 在一定数量的字符后切断文本失败
Cut off text after a certain amount of characters via substr fail
我有一个 wordpress 新闻网站,我必须在一定数量的字符后剪切文本。通过 substr()
一切正常,但是当少于 x 个字符时,它会发疯并在下一个 <li>
的 link 中生成一个废话].
这是代码:
echo '<li>', get_the_date( 'd.m.Y', $recent["ID"] ), ' <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
$post_id = $recent["ID"];
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo mb_substr(do_shortcode( $content ), 0, 200 , "utf-8");
echo "...<br> <br>";
echo "</div>";
$content里面有没有HTML?如果是这样,那被砍掉,它会使下一个 'li' 无效 HTML,也许...刚找到这个,可能会有帮助
Remove all html tags from php string
我有一个 wordpress 新闻网站,我必须在一定数量的字符后剪切文本。通过 substr()
一切正常,但是当少于 x 个字符时,它会发疯并在下一个 <li>
的 link 中生成一个废话].
这是代码:
echo '<li>', get_the_date( 'd.m.Y', $recent["ID"] ), ' <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
$post_id = $recent["ID"];
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo mb_substr(do_shortcode( $content ), 0, 200 , "utf-8");
echo "...<br> <br>";
echo "</div>";
$content里面有没有HTML?如果是这样,那被砍掉,它会使下一个 'li' 无效 HTML,也许...刚找到这个,可能会有帮助
Remove all html tags from php string