You are here: Re: Limit length of echo call « HTML « IT news, forums, messages
Re: Limit length of echo call

Posted by Toby Inkster on 05/22/06 09:49

samir.doshi wrote:

> I have job descriptions saved to my database table and want to call
> them to output them to a table but only want to output a portion of the
> saved job description....like the first 200 letters.

As you use the term 'echo' I'm going to assume you use PHP. ('echo' also
exists in shell scripting and DOS batch files, though they are not
generally noted for their database connectivity. Probably some other
languages use an 'echo' command too.) In future please specify what
language you're using -- you are likely to get more/better answers that
way.

In PHP, there exists a function substr(). (Almost identical functions
exist in C, Perl, Java and Javascript -- and probably other languages too.)

The syntax of substr() is either:

substr(STRING, START, LENGTH)
substr(STRING, START)

this will find a sub-string of the given STRING, starting at character
START (the characters are numbered from 0). If the LENGTH is given, the
sub-string is limited to that many characters; if not, the sub-string
continues to the end of the given STRING.

Examples:

<?php

$example = 'abcdefghij';

echo substr($example, 3, 2);
// 'de'

echo substr($example, 7, 3);
// 'hij'

echo substr($example, 7, 100);
// 'hij'

echo substr($example, 6);
// 'ghij'

echo substr($example, 0, 3);
// 'abc'

?>

So to limit your job description to 200 characters, you want to use:

<?php
echo substr($jobdesc, 0, 200);
?>

You might also want to include an ellipsis (…) character after that:

<?php
echo substr($jobdesc, 0, 200) . '&#8230;';
?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 

Navigation:

[Reply to this 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

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