I have this function to truncate strings longer than a specified parameter. It works with all the strings I passed to it since now.But when I test with the following string I have problems:
Fifth post is the worst ever.Dont you believe?Just read it!
It says:
"Undefined variable:string"  
the function is:
public function limitString($message,$position,$limitString)
{
    if(strlen($message)<$position)
    $string=$message;
    else
    {
    $post = substr($message,$position,1); // Find what is the last character displaying.
    if($post !=" ")
    {
        for($i=$position-1;$i>0;$i--)
        {
          $post = substr($message,$i,1);
          if ($post ==" ")
          {
            break;
          }
        }
        $string=substr($message,0,$i).$limitString;
    }
    }
    return $string; 
}
This is how I call It:
limitString($string,33,"...")
Where am I wrong?
SOLVED: As you guys make me notice The returned $string value wasnt defined outside of
if($post!==' ')
So I added an else statement defining the $string as:
$string=substr($message,0,$position).$limitString;
Thanks Luca