Categories
PHP

preg_replace

preg_replace — Perform a regular expression search and replace

Description

preg_replace ( string|array $pattern , string|array $replacement , string|array $subject [, int $limit = -1 [, int &$count = null ]] ) : string|array|null

Examples

Example #1 Using backreferences followed by numeric literals

<?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
?>

The above example will output:

April1,2003

One reply on “preg_replace”

Leave a Reply

Your email address will not be published. Required fields are marked *