SoFunction
Updated on 2025-03-09

PHP regular function preg_replace parameter description

preg_replace
String alignment parses and replaces.
Syntax: mixed preg_replace(mixed pattern, mixed replacement, mixed subject);
Return value: Mixed type information
Function type: Data processing
Content description
This function uses the pattern rule to parse and compare the string subject, and the string to be replaced as the parameter replacement. The return value is a mixed type data, which is the result of the replaced string.
Usage example
The return value of the following example is $startDate = 6/19/1969
Copy the codeThe code is as follows:

<?php 
$patterns = array("/(19|20\d{2})-(\d{1,2})-(\d{1,2})/", "/^\s*{(\w+)}\s*=/"); 
$replace = array("\\3/\\4/\\1", "$\\1 ="); 
print preg_replace($patterns, $replace, "{startDate} = 1969-6-19"); 
?>