I want to use regular expressions to match the HTML
In the label
The regular expression used is #(.*)#
Because the original text of the match is actually a regular form. I want to put a number of matching results into the database separately
But the returned two-dimensional array I don't understand
My understanding is that the result of the first dimension is the result of a normal match, and then the second dimension is matched in one-dimensional result. But actually, the first-dimensional array is the same as the second-dimensional array.
I found a preg_match parameter
Parameter description:
Parameter description
Pattern Regular Expression
Subject needs to match the retrieved object
Matches optional, stores an array of matching results, $matches [0] will contain text that matches the entire pattern, $matches [1] will contain the text that matches the sub-pattern in the first captured parenthesis, and so on
(o.o analogy your sister Ah can not understand AH beginners let everyone)
The code is as follows
星期一星期二星期三星期四星期五星期六星期日第一大节11121314151617第二大节21;22形势与政策(6)
第10周
吕志和礼堂 白文杰24252627第三大节 英语 数学 第四大节 音乐 晚 上 ";function trimall($str)//删除全部空格{ $qian=array(" "," ","\t","\n","\r");$hou=array("","","","",""); return str_replace($qian,$hou,$str); }$test = trimall($test);$match = "#(.*)#";preg_match_all($match,$test,$TR);print_r($TR);?>
Reply content:
I want to use regular expressions to match the HTML
In the label
The regular expression used is #(.*)#
Because the original text of the match is actually a regular form. I want to put a number of matching results into the database separately
But the returned two-dimensional array I don't understand
My understanding is that the result of the first dimension is the result of a normal match, and then the second dimension is matched in one-dimensional result. But actually, the first-dimensional array is the same as the second-dimensional array.
I found a preg_match parameter
Parameter description:
Parameter description
Pattern Regular Expression
Subject needs to match the retrieved object
Matches optional, stores an array of matching results, $matches [0] will contain text that matches the entire pattern, $matches [1] will contain the text that matches the sub-pattern in the first captured parenthesis, and so on
(o.o analogy your sister Ah can not understand AH beginners let everyone)
The code is as follows
星期一星期二星期三星期四星期五星期六星期日第一大节11121314151617第二大节21;22形势与政策(6)
第10周
吕志和礼堂 白文杰24252627第三大节 英语 数学 第四大节 音乐 晚 上 ";function trimall($str)//删除全部空格{ $qian=array(" "," ","\t","\n","\r");$hou=array("","","","",""); return str_replace($qian,$hou,$str); }$test = trimall($test);$match = "#(.*)#";preg_match_all($match,$test,$TR);print_r($TR);?>
Excuse me, do you understand this sentence?
$matches [1] will contain text that matches the sub-pattern in the first captured parenthesis, what is the parenthesis?
After understanding, I am reminded that your $matches[0] must be more than $matches[1 "TR this label it?"
preg_match_all
It is not a match to stop, but a match to get all the results. So $matches[0]
it is not a string but an array of string. Then each match gets an expression that corresponds to a substring, so [1] is the same.