使用 PHP 删除包含 3 个字符的单词


remove words which consist 3 character using php

请有人帮帮我。

我想使用 php 代码删除由 3 个字符或更少字符组成的单词,请帮助以下句子:

$string = "this is my new minimalist style"

结果必须是"这种新的极简主义风格"

那么我应该使用什么代码来制作它呢?

你可以做:

$string = "this is my new minimalist style"
$string = preg_replace(array('/'b'w{1,2}'b/','/'s+/'),array('',' '),$string);
PHP

>= 5.3的另一个版本(也适用于旧版本,您只需要避免使用匿名函数):

$string = "this is my new minimalist style";
print implode(" ", array_filter(explode(" ", $string), function($item) { return strlen($item) >= 3; }));

这应该做到:

$text = "this is my new minimalist style";
$text = preg_replace("/'b('w{1,2}'s|'s'w{1,2})'b/","", $text);