开发者

match all except some word

i'm looking for a way, to match all except the some word.

please tell me how i must wrote it?

when i wrote

$str = "i am a programmer";
$word = "am";
preg_match_all("/[^($word)]/", $str, $matched);// it do the same, if i when i wrote
preg_match_all("/[^$word]/", $str, $matched);开发者_如何转开发

i also tried preg_match_all("/[^{$word}]/", $str, $matched); but it doesn't do the job.

how can i tell all except that word ?

Thanks Much


Can't you simply remove all occurrences of the word?

str_replace($word, '', $str);

Or split using explode() or preg_split()? This will give you an array with all parts separated by the word.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜