【问题标题】:Show blob file(text + img) in website. From phpbb database在网站中显示 blob 文件(文本 + img)。来自 phpbb 数据库
【发布时间】:2013-04-28 17:47:20
【问题描述】:

我有一个 phpbb 论坛,我想在我的网站上显示最新的 3 个帖子。我可以连接到数据库并检索我想要的内容,但不能从帖子中检索 img。帖子内容存储为 Blob,当我发布帖子时如下所示:

“你好,这是一个测试帖。

[img]http://www.petfinder.com/wp-content/uploads/2012/11/101418789-cat-panleukopenia-fact-sheet-632x475.jpg[/img]

文件结束。"

在论坛中你可以看到文字和图片。但是当我在我的网站上显示帖子时,它看起来像:

(Hello this is a test post. [img:3vv18at0]http://www.petfinder.com/wp-content/uploads/2012/11/101418789-cat-panleukopenia-fact-sheet-632x475.jpg[/img:3vv18at0]End of the file.)

将输入帖子显示为文本,我希望在论坛中看到帖子,文本和图像在他们的位置。

这是我正在使用的代码:

<?php  
     $conexion = mysql_connect("localhost","MYUSER","MYPASS"); 
    $nPost = "0,3";
    //DB a la que me conecto     
    mysql_select_db("DATABASE", $conexion) OR die("No se puede establecer la conexión a MySQL"); 
    $consulta1 = "SELECT * FROM phpbb_topics WHERE forum_id = '4' ORDER BY topic_id DESC LIMIT $nPost";
    $resultado1 = mysql_query($consulta1);
    $consulta2 = "SELECT * FROM phpbb_posts WHERE forum_id = '4' ORDER BY topic_id DESC LIMIT $nPost";
    $resultado2 = mysql_query($consulta2);

    while ($row = mysql_fetch_array($resultado1)) {

    $datosPost = mysql_fetch_array($resultado2);

    $id = "$row[topic_id]";  
    $titulo = "$row[topic_title]"; 
    $respuestas = "$row[topic_replies]";
    $by = "$row[topic_first_poster_name]";
            $text = "$datosPost[post_text]";
    ///////////////////EDIT AND WORKING//////////////////
            $b = preg_replace('#\[img:(.*?)\](.*?)\[/img:(.*?)\]#s', '<br><img  src="$2"/><br> ', $text);
    $c = preg_replace('#\((.*?)\)#s', '$1', $b);        
    $text = $c;
            ////////////////////////THANKS TO damienkeitel//////////////

        echo"<a href='http://www.compraclientes.com/foro/viewtopic.php?f=4&t=$id'><div class='postEntry'><div class='postHeader'><div class='postTitle'>$titulo</div><div class='postOwner'>(By $by)</div> <div class='postReplies'>($respuestas Respuestas)</div></div><div class='postText'>($text)</div></div></a>";  
        } 
    mysql_close($conexion);         
    ?>

非常感谢

【问题讨论】:

  • mysql_* 已被弃用,请尽快迁移到mysqli 或PDO
  • 你的 blob 字段是哪一个?一个 blob 包含图像的二进制文件。您只需将该字段的数据放入图像源中
  • $text = "$dataPost[post_text]";这是 blob 字段。
  • 拆分 $dataPost[post_text] 然后将其设为数组或使用 jquery 并将 [img:3vv18at0] 替换为 html。

标签: php blob phpbb3


【解决方案1】:
$a = "(Hello this is a test post. [img:3vv18at0]http://www.petfinder.com/wp-content/uploads/2012/11/101418789-cat-panleukopenia-fact-sheet-632x475.jpg[/img:3vv18at0]End of the file.)";
$b = preg_replace('#\[img:(.*?)\](.*?)\[/img:(.*?)\]#s', '<br><img src="$2"/><br> ', $a);

$c = preg_replace('#\((.*?)\)#s', '$1', $b);
echo $c;

http://www.damienkeitel.com/pr.php

【讨论】:

    【解决方案2】:

    我相信我之前的一个答案(稍作修改)可以为您提供所需的信息。

    Display the 5 most recent posts on an external page

    您的问题的简短答案是这段代码。这将清理数据的各个方面。

         $topic_title       = $posts_row['topic_title'];
         $post_author       = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
         $post_date          = $user->format_date($posts_row['post_time']);
         $post_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $posts_row['post_id'] . "#p" . $posts_row['post_id']);
    
         $post_text = nl2br($posts_row['post_text']);
    
         $bbcode = new bbcode(base64_encode($bbcode_bitfield));         
         $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);
    
         $post_text = smiley_text($post_text);
    

    正如我在上一个答案中提到的,该代码基于Example 4 PHPBB Wiki。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-03
      • 2022-09-23
      • 2017-04-18
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多