We are learningPHP ereg_replace () function prototype: String ereg_replace (String $pattern, String $replacement, String $string)
String Eregi_replace (String $pattern, String $replacement, String $string)
PHP ereg_replace () function C and replace the matched result with $replacement. When a pattern cell (or sub-mode) is included in a $pattern, the position of the $replacement, such as "1" or "$", is replaced by the contents of those sub-patterns that are matched in turn. "or" $ "means the contents of the entire matching string. It is important to note that the backslash is used as an escape character in double quotes, so it must be in the form of "\1".
Eregi_replace () and the PHP ereg_replace () function are functionally consistent, except that the former ignores case. Code 6.6 is an applied example of this function, which demonstrates how to do a simple cleanup of the program source code.
PHP ereg_replace () function code 6.6 Cleanup of source code
- < ? PHP
- $ Lines = file (' source.php ');//Read the file into the array
- For ($i=0; $i<count($lines); $i + +)
- {
- Remove comments that begin with "\" or "#" at the end of the line
- $lines [$i] = Eregi_replace ("(//|#). *$", "", $lines [$i]);
- Eliminate whitespace at the end of a line
- $lines [$i] = Eregi_replace ("[nrtvf]*$", "RN", $lines [$i]);
- }
- Finishing output to Page
- Echo Htmlspecialchars (Join ("", $lines));
- ?>
The above is a description of the usage of the PHP ereg_replace () function.
http://www.bkjia.com/PHPjc/446249.html www.bkjia.com true http://www.bkjia.com/PHPjc/446249.html techarticle We are learning PHP ereg_replace () function prototype: String ereg_replace (String $pattern, String $replacement, String $string) string eregi_ Replace (string $pattern, String $replaceme ...