Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Echo Variable, But limit words 1

Status
Not open for further replies.

krappleby025

Programmer
Sep 6, 2001
347
NL
Hi all,

i have a script, which pulls a record from the database, there may be 1000 words in the field in teh database.

At the moment the script pulls the entire field and places it into the varable

$rowgetdayjob['JOB_DESCRIPTION']

Now.. what i need to do is when i echo the above i display the entire field, but the area is not big enough. i need to limit the number of words/letters that are displayed on the page..

Can anyone tell me how to do this.. Do i need to do it in the DB request. and if so what code

or can i do it and set a new variable with only the letters that have been selected..

cheers
 
hi,

you can do it with database (depends about the server).

Or you can use substr() php function:
Code:
$NN = 100 ; // number of chars
echo substr($rowgetdayjob['JOB_DESCRIPTION'], 0, $NN);

___
____
 
Just in case you're interested... when I have something of that sort I prefer this code.
Code:
$max_len = 100;
if (srlen($string_to_display) > ($max_len - 3))
{
  $string_to_display=substr($str_to_display,$max_len-3);
  $string_to_display.= '...';
}

So that the user has some notification that the information was truncated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top