dongpo1216 2013-09-10 13:30
浏览 56
已采纳

在我的自定义博客中创建BBCode样式的标签

I want to create BBCode kind of tags for my custom Blog system. However I have no Idea where to start from. I'm not asking for the full working script or anything (if it's a long code whitch it probably is), but I want to know what do I need and some basic leads to get me going. Thanks for all the hints!

This is the code that I'm wanting to add it to:

    $query=$db->prepare("SELECT post_id, title, LEFT(body, 400) AS body, category FROM posts INNER JOIN categories ON categories.category_id=posts.category_id ORDER BY post_id DESC LIMIT $start, $per_page");
        $query->execute();
        $query->bind_result($post_id, $title, $body, $category);    
while($query->fetch()):
        $lastspace = strrpos($body, ' ');?>
    <article>
    <div class="5pxPadding">
    <h2><?php echo "<a href='post.php?id=$post_id'>$title</a>";?></h2>
    <?php echo "Category: ", $category;?>
    <?php echo "<br><br>";?>
    <p><?php
//END BBCODE, ECHO POST
    $body_sub = substr($body, 0) . "<br><br><a href='post.php?id=$post_id'> Continue Reading →</a>";
    echo nl2br($body_sub); ?></p>
    <?php echo "<hr>" ; ?>
    </div>
</article>

I know the code is messy btw, you don't need to tell me that.

  • 写回答

1条回答 默认 最新

  • dqxuiq7772 2013-09-10 13:43
    关注

    You could probably do it kind of like this:

    $str = 'this is a string with [bold]bold[/bold] text';
    $str = preg_replace('/(\[bold\])/', '<strong>', $str );
    $str = preg_replace('/(\[\/bold\])/', '</strong>', $str );
    echo $str;
    

    I'm not great at regex, so I'm sure some wizard can combine my two statements into one, but this is the general idea. Just replace any bbcode with the proper html?

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Java中消息和缓存如何使用
  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路