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 $ pattern contains a pattern unit (or child mode), the position in $ replacement, such as "1" or "$1", will be replaced by the content matched by these child modes in sequence. "" Or "$0" indicates the content of the entire matching string. Note that the backslash in double quotation marks is used as an escape character, so the format of "\ 0" and "\ 1" must be used.
Eregi_replace () and PHP ereg_replace () functions are the same, except that the former is case-insensitive. Code 6.6 is an application instance of this function. This Code demonstrates how to clean up the source code of the program.
PHP ereg_replace () function code 6.6 source code cleaning
- <? Php
- $ Lines = file ('source. php'); // read the file into the array.
- For ($ I = 0; $ I <count ($ lines); $ I ++)
- {
- // Remove the comment starting with "\" or "#" at the end of the line
- $ Lines [$ I] = eregi_replace ("(// | #). * $", "", $ lines [$ I]);
- // Eliminate the white space at the end of the row
- $ Lines [$ I] = eregi_replace ("[nrtvf] * $", "rn", $ lines [$ I]);
- }
- // Output to the page after sorting
- Echo htmlspecialchars (join ("", $ lines ));
- ?>
The above describes the usage of the PHP ereg_replace () function.