functions-online

preg_replace

description

Searches $subject for matches to $pattern and replaces them with $replacement.

declaration of preg_replace

mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit ] [, int &$count ] )

test preg_replace online













share preg_replace

comments for preg_replace

On 24. Jun 2014 18:58 Florian wrote:

Nice tool, good job :) One small remark though. If you try to use backreference it wont work as you'd expect, here is the code generated for these values: $pattern => /the (dog|rat|duck) is ill/ $replacement => A \${1} is running $subject => the dog is ill preg_replace('/the (dog|rat|duck) is ill/', 'A \\${1} is running', 'the dog is ill', -1, $count); It fails because the $replacement (i.e 'A \\${1} is running') is set between simple quotes and not double quotes, also because of the backslash added.

On 16. May 2014 09:48 Mira wrote:

@butzi: Thank you. You are right. Works now perfect.

On 04. May 2014 17:00 butzi wrote:

@Mira: Please take a look at the manual. The $pattern ist required to be encapsulated in some special characters (mostly @ or / is used). Anyway else you get the error message.

more comments for preg_replace

There are some more comments for preg_replace(). To see them all click here.

+

Leave your comment