سؤال

I have a phpbb forum and I want to show the latest 3 post in my website. I can connect to the DB and retrieve what I want but not img from post. Post content is stored as Blob, when I do a post looks like:

"Hello this is a test post.

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

End of the file."

In the forum you can see the text and the image. But when I show the post in my website it looks like:

(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.)

Show the entery post as text, I would like to see the post as in the forum, text and images in their places.

This is the code I am using:

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

Thank you very much

هل كانت مفيدة؟

المحلول

$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 <-- demo

نصائح أخرى

I believe one of my previous answers, slightly modified, can provide you with information you need.

Display the 5 most recent posts on an external page

The short answer to your question is this chunk of code. This will clean up various aspects of your data.

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

As I mention in the previous answer, that code is based on Example 4 the PHPBB Wiki.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top