A brief analysis of PHP regular expression function Library _php tutorial

Source: Internet
Author: User
Tags ereg php regular expression posix vars
Simple analysis of PHP regular expression function library what is it? Here we introduce you to the PHP regular Expression function library (POSIX extension) greedy match, which we should note in conditional sub-patterns and many other POSIX extended regular expression syntax that are not supported by attributes.

Warnings in PHP regular expression function library learning:

This class of regular expressions is not safe to use in binary mode. The PCRE function library is available. Regular expressions are used in PHP for complex string manipulation. The functions that support regular expressions are:

Ereg ()

Ereg_replace ()

Eregi ()

Eregi_replace ()

Split ()

Spliti ()

Each of these functions accepts a regular expression string as its first argument. PHP uses POSIX extended regular expressions defined by POSIX 1003.3. The full description of the POSIX regular expression is shown in the man page contained in the Regex directory in the PHP release package. Can be read by commands like man/usr/local/src/regex/regex.7.

Requirements: Support for this extension can be added without the need for an external library file.

Installation warning: Do not change the TYPE unless you know what you are doing.

To activate RegExp support when configuring PHP add--with-regex[=type]. TYPE can be one of System,apache or PHP. PHP is used by default.

PHP's version of Windows has built-in support for this extension. You can use these functions without having to load any additional extension libraries. Let's take a look at the specific operations:

Run-time configuration: The extension does not define any set directives.

Resource type: The extension does not have any resource types defined.

Predefined constants: The extension does not define any constants.

Examples of PHP regular expression functions:

 
 
  1. //If you find "ABC" anywhere in the $string, return to &true;
  2. Ereg ("abc", $string);
  3. //If $string start with "ABC" then return &true;
  4. Ereg ("^abc", $string);
  5. //If $string end with "abc" &true;
  6. Ereg ("abc$", $string);
  7. //If the user's browser is Netscape 2,3 or MSIE 3 return &true;
  8. Eregi ("(ozilla.[ 23]| MSIE.3) ", $HTTP _user_agent);
  9. //Put three space-delimited words into $regs [1], $regs [2] and $regs [3]
  10. Ereg ([[: alnum:]]+) ([alnum:]]+)
  11. ([[: alnum:]]+) ", $string , $regs );
  12. Will
    Mark at the beginning of the $string
  13. $string = ereg_replace ("^", "
    ", $string);
  14. Will
    Mark to end of $string
  15. $string = ereg_replace ("$", "
    ", $string);
  16. //Delete all line breaks in the $string
  17. $string = ereg_replace ("n", "", $string);
  18. ?>

The introduction to the PHP regular expression function introduces you to this, and hopefully it will help you understand and learn about the PHP regular expression functions.


http://www.bkjia.com/PHPjc/446591.html www.bkjia.com true http://www.bkjia.com/PHPjc/446591.html techarticle simple analysis of PHP regular expression function library what is it? Here we introduce you to PHP regular expression function library (POSIX extension) greedy match, we should note that in conditional sub-mode and many other ...

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