Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从字符串中删除单词,如果它们超过 20 个字符。我已经尝试过了,但它只会添加换行符。
wordwrap($line,30,"",true);
$str = 'asd qqqqqqqqqqqqqqqqq weq'; var_dump(preg_replace('~\b\S{5,}\b~', '', $str));
上面的代码删除了超过 5 个连续非空格字符的所有内容。将 5 替换为 30,你会得到你想要的