There are many answers on this problem, but i found one very easy to implement, lightweight, and fast.
I think the fewer code lines, the better, so why not using a regexp instead of substr?
function substr_wb($string, $length){ preg_match("/^(.{1,$length})\b/u", $string, $matches); return $matches[1]; }
No comments:
Post a Comment