Reply to Re: Limit length of echo call

Your name:

Reply:


Posted by Toby Inkster on 05/22/06 21:21

Jonathan N. Little wrote:

> <?php
>
> if(strlen($jobdesc)>200){
> echo substr($jobdesc, 0, 200) . '&#8230;';
> }
> 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) . '&#8230;';
else
echo $jobdesc;
?>

And I suppose we should be escaping any special characters...

<?php
if (strlen($jobdesc)>220)
echo htmlentities(substr($jobdesc, 0, 200)) . '&#8230;';
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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация