将字符串回显到某一点

时间:2014-10-06 21:37:09

标签: php html

所以我的数据库中有一些文字是这样读的:

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; ?>

谢谢!

1 个答案:

答案 0 :(得分:0)

好像你正在回复来自php的db查询。请在下次更具描述性。如果您有查询返回的字符串类型,则可以使用substring function。这将在特定点切断字符串,并仅回显该数量。

另一种针对您的案例的替代方案是explode function。如果您的查询是$ string,

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