PHP ereg_replace () function working principle _php Tutorial

Source: Internet
Author: User
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

 
 
  1. < ? PHP
  2. $ Lines = file (' source.php ');//Read the file into the array
  3. For ($i=0; $i<count($lines); $i + +)
  4. {
  5. Remove comments that begin with "\" or "#" at the end of the line
  6. $lines [$i] = Eregi_replace ("(//|#). *$", "", $lines [$i]);
  7. Eliminate whitespace at the end of a line
  8. $lines [$i] = Eregi_replace ("[nrtvf]*$", "RN", $lines [$i]);
  9. }
  10. Finishing output to Page
  11. Echo Htmlspecialchars (Join ("", $lines));
  12. ?>

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.