Just how can I access the suits when making use of preg_replace in PHP?

I am attempting to order the uppercase of a number of words and also cover them in period tags. I am making use of preg_replace for extract and also covering objectives, yet it's not outputting anything.

preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str)
0
2019-05-03 17:48:40
Source Share
Answers: 2

From the preg_replace documentation on php.net :

substitute might have referrals of the kind \ n or (given that PHP 4.0.4 ) $n,. with the last kind being the. favored one. Every such reference. will certainly be changed by the message recorded. by the n'th parenthesized pattern.

See Flubba's instance.

0
2019-05-07 18:07:08
Source

You require to place the pattern in parentheses /([A-Z])/, similar to this :

preg_replace("/([A-Z])/", "<span class=\"initial\">$1</span>", $str)
.
0
2019-05-07 16:29:06
Source