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 php 将rtmp协议转hls协议,无法播放
  • ¥15 miniconda安装不了
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?
  • ¥15 微信支付转账凭证,如何解决
  • ¥15 在win10下使用指纹登录时,界面上的文字最后一个字产生换行现象
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,下面有仿真图,请根据仿真图来设计c语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word