...

View Full Version : Dots ..... after a substr output



Cacus
10-26-2006, 11:08 PM
Hi All

Can any one help. I have a search box on my web site that echos a small part of the details, like google. I use the following for the echo.


<?php echo substr(($row_articles['bodytext']),0,260); ?>

I then add dot .... with html but should the field be empty I would get the following:

Hislop
HISLOP.—At Goole Maternity Home, on Friday, Sept. 7th, to John and Nora (nee Sheard), a son. ...
www.starlightpublishing.co.uk/thehistoryfiles/bmds/England/bmds.php?id=3

Hislop
...
www.starlightpublishing.co.uk/thehistoryfiles/bmds/England/bmds.php?id=3


Is there a command that will allow the substr to insert dots only when something is echoed back that would output as such:


Hislop
HISLOP.—At Goole Maternity Home, on Friday, Sept. 7th, to John and Nora (nee Sheard), a son. ...
www.starlightpublishing.co.uk/thehistoryfiles/bmds/England/bmds.php?id=3

Hislop
www.starlightpublishing.co.uk/thehistoryfiles/bmds/England/bmds.php?id=3



Cheers
Steve

Brandoe85
10-26-2006, 11:15 PM
Hi,

You could use strlen(), if it's greater than 260 concatenate the dots, otherwise only display the text:


<?php echo (strlen($row_articles['bodytext']) > 260) ? substr(($row_articles['bodytext']),0,260) . '. ...' : $row_articles['bodytext']; ?>
Ref:
http://us2.php.net/strlen

Good luck;

Cacus
10-27-2006, 08:43 AM
Cheers.

Will give it a go later

Steve



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum