Maybe I'm not getting the question but is this the expected result?
function title_resize($text, $max_length = 15, $fulltext = false)
{
if ($fulltext)
{
return $text;
}
else
{
return substr($text, 0, $max_length) . '...';
}
}
$str = "this item is for sale";
var_dump(title_resize($str, 10));