[solved] Display first 30 words of a large string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

[solved] Display first 30 words of a large string?

Post by Sindarin »

How can I show the first 30 words of a large string?

Like "This is my big text" will become "This is my big..."

I tried an algorithm but it seems there are some conflicts with tiny mce's output and nothing gets displayed at all.
Last edited by Sindarin on Sat Aug 30, 2008 4:04 am, edited 1 time in total.
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: Display first 30 words of a large string?

Post by The_Anomaly »

This is in the Useful Posts sticky in this forum. Seems to be exactly what you want.
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Display first 30 words of a large string?

Post by ghurtado »

Refer to the other thread you started about this, and where I already posted a solution to your problem.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Display first 30 words of a large string?

Post by Sindarin »

Refer to the other thread you started about this, and where I already posted a solution to your problem.
I guess I can make it remove characters not words. :|


This worked:

Code: Select all

 $maxchars=300;
  if (strlen (($newscontent)) > $maxchars)
  {
  $newscontent=substr($newscontent, 0, $maxchars);
  $newscontent=$newscontent." ...<a href='edit.php?id=$newsid'><br/>More...</a>";
  }
I guess it's okay for now.
Post Reply