I want to use a regular expression to match the regular expression in the html tag. the regular expression is #(. *) # because the original matching text is actually a regular table, I want to save the matching results to the database separately, but the returned two-dimensional array I don't understand. the result is positive... I want to use a regular expression to match html
Label
The regular expression used is #(.*)#
Because the matched original text is actually a regular table, I want to save the matching results to the database separately.
But I don't understand the returned two-dimensional array.
My understanding is that the result of the first dimension is the result of normal matching, and then the second dimension is in the result of the one dimension. but actually, the first dimension array is the same as the second dimension array. ah
I found a preg_match parameter.
Parameter description:
Parameter description
Pattern regular expression
The subject must match the retrieved object.
(Optional) matches. it stores an array of matching results. $ matches [0] will contain the text that matches the entire pattern, $ matches [1] will contain the text that matches the child pattern in the first captured bracket, and so on
(O. o and so on. you can't understand it. beginners can help everyone)
The code is as follows:
MondayTuesdayWednesdayThursdayFridaySaturdaySundaySection 111121314151617Section 221;22Situation and Policy (6)
Week 1
Lu Zhi and Bai Wenjie of the auditorium24252627Section 3 English Mathematics Section 4 Music Later "; Function trimall ($ str) // delete all spaces {$ 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 a regular expression to match html
Label
The regular expression used is #(.*)#
Because the matched original text is actually a regular table, I want to save the matching results to the database separately.
But I don't understand the returned two-dimensional array.
My understanding is that the result of the first dimension is the result of normal matching, and then the second dimension is in the result of the one dimension. but actually, the first dimension array is the same as the second dimension array. ah
I found a preg_match parameter.
Parameter description:
Parameter description
Pattern regular expression
The subject must match the retrieved object.
(Optional) matches. it stores an array of matching results. $ matches [0] will contain the text that matches the entire pattern, $ matches [1] will contain the text that matches the child pattern in the first captured bracket, and so on
(O. o and so on. you can't understand it. beginners can help everyone)
The code is as follows:
MondayTuesdayWednesdayThursdayFridaySaturdaySundaySection 111121314151617Section 221;22Situation and Policy (6)
Week 1
Lu Zhi and Bai Wenjie of the auditorium24252627Section 3 English Mathematics Section 4 Music Later "; Function trimall ($ str) // delete all spaces {$ 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);?>
Have you understood this sentence?
$ Matches [1] will contain the text that matches the child pattern in the first captured bracket. what does the bracket mean?
After understanding this, I am reminding you that your $ matches [0] must have more TR tags than $ matches [1?
preg_match_allInstead of stopping a match, all results are obtained after matching. So$matches[0]It is not a string but an array of string. Then, each matching expression corresponds to a substring. Therefore, the same applies to [1.