[Solved] Make string shorter. Cut it by the last word [duplicate]


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;

http://codepad.org/NP9t4IRi

solved Make string shorter. Cut it by the last word [duplicate]