将字符串回声到某个点


Echo out string up to a certain point

所以我的数据库中有一些文本,读起来像这样:

This is my very first blog post, <b>Ever!</b>
<rm>
This content is after the rm and should not be seen on the home page. That would just make for too much info on the front home page. Don't you agree?

现在这个文本是在撒谎,我如何才能让回声停止在虚构的标签上?

我希望它在This is my very first blog post, <b>Ever!</b>或标签处停止。

我有以下代码

<?php if($posts): ?>
        <?php foreach($posts as $post): ?>
            <h3><a href="/post/<?php echo $post->id; ?>"><?php echo $post->title; ?></a></h3>
            <span><?php echo $post->body; ?><span>
            <hr/>
        <?php endforeach; ?>
    <?php else: ?>
        <p>No Recent Posts</p>
    <?php endif; ?>

谢谢!

您似乎在从php中回声数据库查询。下次请多描述一下。若查询返回了字符串类型,则可以使用子字符串函数。这将在某个点切割字符串,并且只回声该量。

另一个特定于您的案例的替代方案是爆炸函数。如果您的查询是$string,

<h3><a href="/post/<?php echo $post->id; ?>"><?php list($post->title) = explode('<rm>', $post->body); echo $post->title; ?></a></h3>