drwj4061 2014-10-06 21:37
浏览 13
已采纳

将字符串回显到某一点

So I have some text in my database that is reading like so:

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?

Right now this text is lying, how can I make the echo stop at the made up tag?

I want it to stop at This is my very first blog post, <b>Ever!</b> or at the tag.

I have the following code

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

Thanks!

  • 写回答

1条回答 默认 最新

  • duanhe1965 2014-10-06 21:41
    关注

    It seems like you are echo'ing a db query from php. Please be more descriptive next time. If you have a string type returned from query, you can use the substring function. This will cut the string at a certain point and only echo that amount.

    Another alternative specific to your case is the explode function. If your query is $string,

    <h3><a href="/post/<?php echo $post->id; ?>"><?php list($post->title) = explode('<rm>', $post->body); echo $post->title; ?></a></h3>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下