RE: [PHP] Displaying first 100 characters of an article

From: Date: Wed, 04 Oct 2000 04:56:17 +0000
Subject: RE: [PHP] Displaying first 100 characters of an article
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-18517@lists.php.net to get a copy of this message
Hi~ Everything works great except for one aspect. Each time the next article is displayed, it takes the previous article's first 125 characters and prepends them to the current article's first 125 characters. To see what I mean, go to http://www.siualumni.com/news.php. Any ideas? The code I ended up using is: <? // connect to database here $mySQL = "SELECT * FROM news order by date limit 4"; $results = mysql_query($mySQL); while ($myrow=mysql_fetch_array($results)) { $stuff = "$myrow[message]"; if (strlen($stuff)<125) { $retstring = $retstring . $stuff; } else { $retstring = $retstring . substr($stuff,0,125) . '...'; } print "$retstring"; } ?> Thanks, -Ben At 03:30 AM 10/3/2000 -0400, Lawrence.Sheed@dfait-maeci.gc.ca wrote:
How about: $stuff = "my long string here"; if (strlen($stuff)<100) {
        $retstring = $retstring . $stuff;
} else {
                $retstring = $retstring . substr($stuff,0,100) . "...";
} cheers, Lawrence. -----Original Message----- From: Ben Weinberger [mailto:ben@digitalsmiths.com] Sent: October 3, 2000 03:27 PM To: php-general@lists.php.net Subject: [PHP] Displaying first 100 characters of an article Hi~ I'm pulling data out of a MySQL db and displaying it on a web page... the data is like a news article with a title and a body. Currently, I can display the title and I have it linked to a javascript pop-up window that displays the full article. I would like to add the first 100 characters of the article under the title as well... something like follows: Version 6.0 just Released We've worked hard to bring you a new and improved version 6.0 software package so that you.... Is there a way to make those words under the title appear and only display the first 100 characters followed by a "..."? Thanks, -Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#18517) next »