Forum Moderators: coopster

Message Too Old, No Replies

intelligent script to shorten lenght of txt to certain amount of char

         

dmmh

4:16 pm on Dec 11, 2005 (gmt 0)

10+ Year Member



I need something advanced if possible :)

or some ideas how to tackle it myself.

preferably something which can detect paragrahps and not just cut text of at a certain amount of chars :)

ergophobe

6:23 pm on Dec 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This might help:

[webmasterworld.com...]

dmmh

8:11 pm on Dec 11, 2005 (gmt 0)

10+ Year Member



thats a nice starter :)

someone

5:56 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



Coopster wrote this function in the other thread,

function truncate($string, $length = '', $replacement = '...', $start = 180)
{
if (strlen($string) <= $start)
return $string;
if ($length)
{
return substr_replace($string, $replacement, $start, $length);
}
else
{
return substr_replace($string, $replacement, $start);
}
}

I don't understand the if($length) part. $length is equal to a space so if($length) will always be true. In that case, the else part would never be executed. Someone please explain. Thank you!

dmmh

8:55 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



its not equal to a space, $length is empty ( '' ), so if the variable is empty (it wasnt passed a value like: echo truncate($string, '800', $replacement, $start)), the if statement will not be be executed but the else will, if it isnt empty, the if statement will be executed

someone

11:07 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



Thank you, dmmh! I understand it now.