note 12158 deleted from function.ereg-replace by jimw

From: Date: Fri, 02 Nov 2001 01:56:47 +0000
Subject: note 12158 deleted from function.ereg-replace by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20208@lists.php.net to get a copy of this message
REPLACING A MATCH WITH ITSELF PLUS SOMETHING EXTRA using ereg_replace(): This is not explained very clearly in the function definition. Here is an example: $string="FieldNamePlus"; $string=ereg_replace("([a-z])([A-Z])", "\\1xxx\\2" , $string); echo ">>>$string<<<"; This example looks for a match for any lower case letter followed by an upper case letter--ignore the parenthesis around [a-z] and [A-Z] for a second. The \\1 in the replacement string tells the function to include in the replacement string whatever matched what was in the 1st set of parenthesis in the "pattern", and the \\2 in the replacement string tells the function to include in the replacement string whatever matched what was in the 2nd set of parenthesis in the "pattern". So, the ouput from the example is: FieldxxxNamexxxPlus The function replaced the match "dN" with "dxxxN" and the match "eP" with "exxxP"

« previous php.notes (#20208) next »