Im trying to clean up values, as some strings are longer than 70 characters, so I need to cut these of.
the idea is that if the length is longer than 70 cut this of after the last comma(remove this to), but some strings that are longer dont have a comma so these need to be cut of at the last whitespace within the max length of 70 characters so that we dont have partial words.
The code that I have now(not working correctly).
$str = substr($longstr, 0 , 70 , '');
$shortstr = substr($str, 0, strrpos($str.",", ","));
output 1 (with commas)
$longstr = 'Some strings are way to long and need to be cut of, yes realy because we need the space.';
$shortstr = 'Some strings are way to long and need to be cut of';
output 2 (whitepsace)
$longstr = 'Some strings are way to long and need to be cut of yes realy because we need the space.';
$shortstr = 'Some strings are way to long and need to be cut of';