surion Posted April 26, 2007 Share Posted April 26, 2007 hi for work i have to rewrite some stuf, now i find the next function in one of the files: function remove_accents( $string ) { $string = htmlentities($string); $string = preg_replace("/&([a-z])[a-z]+;/i","$1",$string); $string = str_replace("-","",$string); $string = str_replace("'","",$string); $string = str_replace(" ","",$string); return $string; } my question => i don't realy understand that preg_replace function, i know the first variable is a regular expression, and $string is the var where the regular expression should be ran on, but what is that $1 var doing there? since i don't know where it comes from, what it is, what it should be, what it does,... i don't know how to change it to make it work,... and why is it in between quotes? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted April 26, 2007 Share Posted April 26, 2007 1) Check out the "Subpatterns" subsection of PCRE Pattern Syntax 2) The $1 variable contains the parenthetical, captured subpattern in the preceeding pattern. That is, "([a-z])". Whatever letter, if any, is captured there it will be accessible in the replacement string as either $1 (preferred) or \1. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.