|
Posted by Toby Inkster on 05/22/06 21:21
Jonathan N. Little wrote:
> <?php
>
> if(strlen($jobdesc)>200){
> echo substr($jobdesc, 0, 200) . '…';
> }
> else {
> echo $jobdesc;
> }
>
> ?>
Yep -- even better. Though I prefer to allow a little grace for pieces
of text that are only just over the limit. For example:
<?php
if (strlen($jobdesc)>220)
echo substr($jobdesc, 0, 200) . '…';
else
echo $jobdesc;
?>
And I suppose we should be escaping any special characters...
<?php
if (strlen($jobdesc)>220)
echo htmlentities(substr($jobdesc, 0, 200)) . '…';
else
echo htmlentities($jobdesc);
?>
Bonus points for not leaving cutting it so that there are no partial wor...
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|