PHP inherits *nix's consistent tradition and fully supports the processing of regular expressions. Formal expressions provide an advanced, but not intuitive, method for string matching and processing. Friends who have used Perl's regular expressions
Let's take a look at two extraordinary characters: ' ^ ' and ' $ ' they are used to match the beginning and end of the string, respectively, for example:"^the": matches a string that begins with "the";"Of despair$": matches a string ending with "of
Make sure the recurrence occurs
So far, you already know how to match a letter or number, but more likely, you might want to match a word or a group of numbers. A word consists of several letters, and a group of numbers has several singular parts.
contont ppppppp my link contont ppppppp my link contont ppppppp my link
The above code, I need to extract all the contents of the container class baby, the structure is not
Are you sure you already know how to match a letter or number until now, but in more cases, you may need to match a word or a group of numbers. A word may consist of several letters, and a group of numbers may consist of several singular numbers.
Use regular expressions to match characters. if you replace all the characters, you can use preg_replace. But now I want to randomly replace one of the multiple matched results, which is a little troublesome. I wrote a function to solve the problem.
I. Characteristics of String types
1, PHP is a weakly typed language, other data types can be directly applied to string function operation.
1:
2:echo substr ("123456", 2,4); Output 345 3:echo substr (123456,2,4); Output 345
Look at the case study regular expression
First, let's take a look at two special characters: ' ^ ' and ' $ ' they are used to match the start and end of the string, respectively, to illustrate the following:
First, let's take a look at two special
?? Summary ?? Regular expressions are powerful tools for pattern matching and exchange. Regular expressions allow users to construct matching modes by applying a series of special characters, and then input matching modes to data files and programs,
There are several possibilities for the original:
[font= "Microsoft Yahei" onclick= "alert (' B ')"] People's Republic of China [/font]
[font= "abc" onclick= "Alert (' B ')"] People's Republic of China [/font]
[font= "Microsoft Yahei"] People's
Make sure the recurrence occurs
So far, you already know how to match a letter or number, but more likely, you might want to match a word or a group of numbers. A word consists of several letters, and a group of numbers has several singular parts.
You can use the PHP internal function trim () to remove the leading and trailing spaces of the string (). However, we often want to completely clear the blank. You need to clear the white spaces at the beginning and end, change multiple white spaces
This program is actually an important part of the "thief program. This program is just a part of downloading remote images. The program is easy to write and comments are made in most parts.
Copy codeThe Code is as follows: if (preg_match_all ("/http:
Matching regular expressions for Chinese characters: [U4E00-U9FA5]
Match Double-byte characters (including Chinese characters): [^x00-xff]
Application: Computes the length of the string (a double-byte character length meter 2,ascii character 1)
Review Regular expressions are a powerful tool that can be used for pattern matching and substitution. Regular expressions allow the user to build a matching pattern by using a series of extraordinary characters, then compare the matching pattern
To determine repeat occurrences
Until now, you already know how to match a letter or number, but more often than not, you might want to match a word or a set of numbers. A word consists of several letters, and a set of numbers has several singular
Character of a String type
1, PHP is a weak type language, other data types can generally be directly applied to string function operations.
echo substr ("123456", 2,4); Output 345echo substr (123456,2,4); Output 345echo Hello; First look for the
Recently, the boss called a small exercise in data checking, which involves extracting the Chinese text section from a file containing a Chinese text segment and storing it, using PHP for development. The middle involves php regular expression
There are two ways to handle regular text in PHP, one is the pcre approach (the Pcre library is a set of functions that implements a regular expression pattern matching feature that is slightly different from the syntax and semantics of Perl 5 (see
Parse regular expressions and pattern matching in PHP. In PHP, two methods are provided for regular expression processing text. one is PCRE (the PCRE library implements a slightly different syntax and semantics from perl5 (see below) the regular
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.