Home > Backend Development > PHP Tutorial > Regular expressions commonly used in PHP for making dynamic web pages_PHP tutorial

Regular expressions commonly used in PHP for making dynamic web pages_PHP tutorial

WBOY
Release: 2016-07-15 13:22:35
Original
1016 people have browsed it

Regular expression for matching Chinese characters: [u4e00-u9fa5]

Matching double-byte characters (including Chinese characters): [^x00-xff]

Application: counting characters The length of the string (the length of a double-byte character is counted as 2, and the length of an ASCII character is counted as 1)

动态网页制作PHP常用的正则表达式

Regular expression to match empty lines: [s| ]*

Match Regular expression for HTML tags: /<(.*)>.*|<(.*) />/

Regular expression for matching leading and trailing spaces: (^ s*)|(s*$)

Application: There is no trim function like vbscript in JavaScript, we can use this expression to achieve it, as follows:

动态网页制作PHP常用的正则表达式

Use regular expressions to decompose and convert IP addresses:

The following is a javascript program that uses regular expressions to match IP addresses and convert IP addresses into corresponding values:

动态网页制作PHP常用的正则表达式

However, if the above program does not use regular expressions, it may be simpler to use the split function to decompose it directly. The program is as follows:

动态网页制作PHP常用的正则表达式

Matching email addresses Regular expression: w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*

Regular expression matching URL: http: //([w-]+.)+[w-]+(/[w- ./?%&=]*)?

An algorithm for removing repeated characters from a string using regular expressions Program:

动态网页制作PHP常用的正则表达式

A javascript program that uses regular expressions to extract file names from URL addresses. The following result is page1

动态网页制作PHP常用的正则表达式

Use regular expressions to limit the input content of the text box in the web form:

Use regular expressions to limit the input to Chinese only:

动态网页制作PHP常用的正则表达式

Use regular expressions Limit the input of only full-width characters:

动态网页制作PHP常用的正则表达式

Use regular expressions to limit the input of numbers:

动态网页制作PHP常用的正则表达式

Use regular expressions Only numbers and English can be entered:

动态网页制作PHP常用的正则表达式


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446958.htmlTechArticleRegular expression matching Chinese characters: [u4e00-u9fa5] Matches double-byte characters (including Chinese characters) : [^x00-xff] Application: Calculate the length of a string (the length of a double-byte character counts as 2,...
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