Let's say we have following sample string:
We have words such as fname, lname, age and year, salary, nancy, davolio, erin, borakova, tony, raphael
What I need to do is, to get the part of the string until last occurence of ,
delimiter and result must be up to 70th characters.
So for sample text, result must be like:
We have words such as fname, lname, age and year, salary, nancy
Is there any single function of PHP that does some operation like this?
I tried something like:
$max_allowed_len = 70;
if (strlen($str) > $max_allowed_len) {
$cut_pos = strpos($ico_titles, ',', $max_allowed_len - 20);
$text = substr($str, 0, $cut_pos);
}
But, I think that using
$max_allowed_len - 20
as offset point will not give me exact results.