我有一个 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);
?>
非常感谢