1

我有一个 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);         
    ?>

非常感谢

4

2 回答 2

0
$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 <-- 演示

于 2013-04-29T17:37:34.423 回答
0

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

在外部页面上显示 5 个最新帖子

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

     $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);

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

于 2013-04-29T17:01:55.993 回答