![]() |
|
|
|
#1 |
|
Hello,
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. How can I do that? Thanks samir.doshi@gmail.com |
|
|
|
|
#2 |
|
Posts: n/a
|
|
|
|
|
#3 |
|
Posts: n/a
|
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. > > How can I do that? Depends on your language. In PHP, it would be: substr() echo substr($jobdesc, 0, 200); -- -bts -Warning: I brake for lawn deer |
|
|
|
#4 |
|
Posts: n/a
|
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) . '…'; ?> -- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact |
|
|
|
#5 |
|
Posts: n/a
|
Toby Inkster wrote:
> You might also want to include an ellipsis (…) character after that: > > <?php > echo substr($jobdesc, 0, 200) . '…'; > ?> > or maybe: <?php if(strlen($jobdesc)>200){ echo substr($jobdesc, 0, 200) . '…'; } else { echo $jobdesc; } ?> -- Take care, Jonathan ------------------- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com |
|
|
|
#6 |
|
Posts: n/a
|
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 |
|