FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Read more...





pollux1er
I want to contract a text taken from the database. How to make such an operation using php functions?
imagefree
Did you mean this?
i was using it in my script, its gift 4 u. Very Happy


Code:
function short_name($string , $width_length )
{
   if(strlen($string) > $width_length )
      $string=substr($string , 0 , $width_length - 2 ).'...';
   return $string;
}


$short_text = short_name(stripslashes($row['mysql_field']) , 18 );


$width_length means the maximum characters that can take place on a given area. 2 is subtracted from if afterwords to make space available for ...'.
pollux1er
Thanks a lot! I will rapidly try it and see!
ilesinge
You may also want to keep words unbroken :

Code:
function crop_text($string, $length){
   //Where "<<cut>>" is a string you are sure will never be in your input
   list($cropped_string) = explode("<<cut>>", wordwrap($string, $length, "<<cut>>",1));
   return $cropped_string;
}
pollux1er
ilesinge wrote:
You may also want to keep words unbroken :

Code:
function crop_text($string, $length){
   //Where "<<cut>>" is a string you are sure will never be in your input
   list($cropped_string) = explode("<<cut>>", wordwrap($string, $length, "<<cut>>",1));
   return $cropped_string;
}


The one imafree gave me works fine but thanks a lot for this complementary help to make it look better! Wink
Related topics
Do you read comics? What title?
Who`s like read books??
Dune, Ever read its briliance?
Harry Potter, Are you into it?
please read this topic very interest
Mark all forums read
How often do you read sci-fi for pleasure?
Jonathan Livingston Seagull
a nice story that can get you thinking... read to find out
Marketplace Blacklist! - Read to avoid being scammed!
The worst book you've ever read
Please read this first
Anybody ever read the book The Sight?
Don't Read Very Often but..
How control my pagina and I read email use the control panel
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.