Jump to content

[SOLVED] need to limit a certain amount of characters on display...


Noskiw

Recommended Posts

<?php

$title = "Blog";

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("blog", $connect) or die(mysql_error());

function bbcode($string)
{


    if ($string) {


        $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]',
            '

', '', '', ':P');

 

 

        $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>',

            '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">',

            '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />');

 

 

        $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string);

 

 

        return $new_string_2;

 

 

    }

}

 

echo "<h1>Blog</h1>\n";

 

$query = mysql_query("SELECT * FROM blog");

 

if (mysql_num_rows($query) == 0) {

    echo "<hr />There are no posts yet, make the first in the admin section!\n";

} else {

    while ($row = mysql_fetch_assoc($query)) {

    echo "<hr />";

    $title2 = $row['title'];

    $name = $row['name'];

    $email = $row['email'];

        $post = $row['post'];

        $date = $row['date'];

        $time = $row['time'];       

           

        echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(wordwrap($post, 118, "<br />", true)))) . "</td></tr></table>\n";       

    }

}

 

echo "<hr />\n";

 

echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n";

 

?>[/code]

 

I want to limit "$post" to a certain amount of characters (say 200) and then say "... Read More" after it, but to be completely honest, I wouldn't know how to do it. I wish I did.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.