Home > Backend Development > PHP Tutorial > Introduction to common functions of PHP regular expressions

Introduction to common functions of PHP regular expressions

WBOY
Release: 2016-07-25 08:59:09
Original
1033 people have browsed it
  1. preg_match_all("|<[^>]+>(.*)]+>|U", "
    ", $out, PREG_PATTERN_ORDER);
  2. print $out[0][0].", ".$out[0][1]."n";
  3. print $out[1] [0].", ".$out[1][1]."n"
  4. ?>
Copy code

3, preg_replace string comparison parsing and replacement.

Syntax: mixed preg_replace(mixed pattern, mixed replacement, mixed subject);

Return value: Mixed type data

Function type: Data processing

Description: This function uses pattern rules to parse and compare the string subject, and the string to be replaced is the parameter replacement. The return value is mixed type data, which is the string result after substitution.

Usage example, the return value in the following example is $startDate = 6/19/1969.

  1. $patterns = array("/(19|20d{2})-(d{1,2})-(d{1,2})/", "/^ s*{(w+)}s*=/");
  2. $replace = array("3/4/1", "$1 =");
  3. print preg_replace($patterns, $replace, "{startDate} = 1969 -6-19");
  4. ?>
Copy code

4, preg_split splits the string according to the specified rules.

Syntax: array preg_split(string pattern, string subject, int [limit]);

Return value: array

Function type: Data processing

Description: This function can separate strings according to specified rules. The return value after cutting is an array variable. The parameter pattern is the specified rule string, the parameter subject is the string to be processed, and the parameter limit can be omitted, indicating the maximum number of consistent values ​​to be processed.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template