Php preg_replace regular expression such as & lt; any characters XXXX any Characters & gt; to determine whether there is an XXXX string. If yes, replace the angle brackets before and after, the output is [any character XXXX any character ., Preg_replace ('/& lt; (. * XXXX .*?) & Gt;/S', '[$1]', $ str php's preg_replace regular expression
For example <Any character xxxx any character> To determine whether the XXXX string exists. If yes, replace the angle brackets before and after, and finally convert it to [any character XXXX any character] output.
------ Solution --------------------
Preg_replace ('/<(. * XXXX. *?)> /S ',' [$1] ', $ str); // prevents greedy matching.
------ Solution --------------------
PHP code
$ Str ="
<Any character xxxx any character>
<Any character zzzz any character>
"; $ K = 'xxxx'; echo preg_replace ("/<([^>] *? {$ K} [^>] *)>/", '[$1]', $ str );