开发者

PHP preg_replace how to combine these two preg statements?

开发者 https://www.devze.com 2023-04-04 08:00 出处:网络
$str = preg_replace(\'/[\\\\r\\\\n!.,\\\'“”;’?-\\s+]/\', \' \', $str); $str=preg_replac开发者_如何学JAVAe(\'/\\s+\\S{1,2}(?!\\S)|(?<!\\S)\\S{1,2}\\s+/\', \'\', $str);
$str = preg_replace('/[\\r\\n!.,\'“”;’?-\s+]/', ' ', $str);
$str=preg_replac开发者_如何学JAVAe('/\s+\S{1,2}(?!\S)|(?<!\S)\S{1,2}\s+/', '', $str);

If I leave them like that is there performance issue also or is it better.?


preg_replace accepts arrays as arguments. The following should be equivalent:

$str = preg_replace(array('/[\\r\\n!.,\'“”;’?-\s+]/', '/\s+\S{1,2}(?!\S)|(?<!\S)\S{1,2}\s+/'), array(' ', ''), $str);
0

精彩评论

暂无评论...
验证码 换一张
取 消