【发布时间】: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。