0

I have the following string that i want to replace parts of:

Blah blah Mr. [-user_first_name-] [-user_last_name-]

This will replace verything [- -]:

preg_replace('/[^\[-[a-z\d_\/A-Z. ]+-\]]/i', '', $body);

My goal is to replace everything that isn't in [- -]

Do you know how I can make this worth?

4

1 回答 1

1

不要使用preg_replace(). 使用preg_match_all()相同的正则表达式并连接结果。

preg_match_all('%\[-[a-z\d_/A-Z. ]+-\]%', $subject, $result, PREG_PATTERN_ORDER);
$result = implode($result[0]);
于 2013-03-04T22:08:54.400 回答