Reputation: 4665
I need to remove words from string, if they're longer than 20 characters. I've tried this but it only adds line breaks.
wordwrap($line,30,"",true);
Upvotes: 0
Views: 953
Reputation: 255005
$str = 'asd qqqqqqqqqqqqqqqqq weq';
var_dump(preg_replace('~\b\S{5,}\b~', '', $str));
The code above removes everything longer than 5 consecutive non-space characters. Replace 5 with 30 and you'll get what you want
Upvotes: 4