Explanation of the preg_match function [wei static charging]

Source: Internet
Author: User

$ Str = 'sdfasfs12333ddd12233 ';

Preg_match ('/\ d/si', $ str, $ arr); // you can specify three consecutive numbers.

Echo '<pre> ';

Print_r ($ arr );

Echo '</pre> ';

1. This function only matches the first value.

2. $ Arr [0] stores the result.


Preg_match_all all results, so it is a two-dimensional array: $ arr [0] [1] stores the first result, $ arr [0] [n] stores the nth result;

$ Arr [1] [0] stores the results of the first subexpression in the first result. $ arr [1] [n] stores the results of n + 1, the result of the first subexpression;

 

Example: The most commonly used knowledge point during wei's static state

$ Str = "111-555-666 dfs5 + fsfffsd-2215affsfsdf ";

Preg_match ('/(\ d) \ 1 {2}-(\ d) \ 2 {2}-(\ d) \ 3 {2}/si', $ str, $ arr); // you must use 'and cannot use' because reverse capture exists.


Second: http: // localhost/wc. php/15,23,45.html:

Method 1: Use a regular table for processing in php; $ _ SERVER [PATH_INFO];

$ Para = $ _ SERVER ['path _ info'];

$ Pattern = '/(\ d) +/si'; // There is a number
$ Pattern = '// (\ d +), (\ d +), (\ d +) \. html $/si ';
Preg_match ($ pattern, $ para, $ arr );

Method 2: Use apache rewrite for processing.

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.