Forum Moderators: coopster

Message Too Old, No Replies

Editing strings

Removing a certain amount of text

         

xeonaphobe

11:22 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Hi everyone,

I've more or less finished developing a flat file based blog, and everything is working quite nicely. I've added a "Recent Articles" list, which displays my last 5 entries.
I'm displaying this list in a fairly small iframe so i'm a bit pushed for space. I'm looking to just list the subject i've set for each entry. This is fine, unfortunatly some of the topic names are longer than i'd like and running off the edge of the frame.
My question is this: would it be possible to cut back on the number of characters in the string?

Eg.
$subject = "PHP is a crazy language";
$newsubject = "PHP is a cra...";

How would I go about this?

Many thanks in advance,
Neil

hughie

11:41 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



here you go based on your new max string length being 10.

if (strlen($subject>10)
{
$newsubject=substr($subject, 0, 10).'...';
}
else
{
$newsubject=$subject;
}

echo $subject;

Cheers,
Hughie

xeonaphobe

11:50 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Fantastic, just what I was after :)

Cheers,
Neil