This should work:
$str = "i have google too";
$strarr = explode(" ", $str);
$res = "";
foreach($strarr as $k)
{
if (strlen($res.$k)<10)
{
$res .= $k." ";
}
else
{
break;
};
}
echo $res;
solved Make string shorter. Cut it by the last word [duplicate]