Question about filtering Chinese characters in php: Is James here. Shift leader: James has a stomachache and asks for leave for half a day. Teacher: What did Wang Lei do. Shift leader: Wang Lei asks for leave for two days. Teacher: Didn't Chen Hua come? Shift leader: Chen Hua has returned to the students.
I want to filter out the instructor's questions. Leave only: shift leader: James has a stomachache and asks for leave for half a day. Shift leader: Wang Lei asks for leave for two days. Shift leader: Chen Hua has returned to the students.
How to write php code in this way.
Reply to discussion (solution)
1.. Array formed at the end
2. in the loop array, replace the regular expression of "instructor" with null.
3. export the array content
Not all of the instructor's questions end with a full stop,
I don't know much about the main book. can I provide code?
It can always end with a shift leader, and can be added when output
If you want to answer questions like this, you only need to merge the array after the end is cut.
$ S = 'teacher: Is James here. Shift leader: James has a stomachache and asks for leave for half a day. Teacher: What did Wang Lei do. Shift leader: Wang Lei asks for leave for two days. Teacher: Didn't Chen Hua come? Shift leader: Chen Hua has returned to the students. '; Echo preg_replace ('/Instructor:. + (shift leader. +)/U', '$ 1', $ s );
Shift leader: James has a stomachache and asks for leave for half a day. Shift leader: Wang Lei asks for leave for two days. Shift leader: Chen Hua has returned to the students.
$ Str = 'Instructor: Is James here. Shift leader: James has a stomachache and asks for leave for half a day. Teacher: What did Wang Lei do. Shift leader: Wang Lei asks for leave for two days. Teacher: Didn't Chen Hua come? Shift leader: Chen Hua has returned to the students. '; $ Arr = explode ('Instructor:', $ str); foreach ($ arr as $ k => $ v) {$ item = mb_strpos ($ v, 'ban', 0, 'gbk'); $ len = mb_strlen ($ v, 'gbk'); $ res = mb_substr ($ v, $ item, $ len, 'gbk'); echo $ res ;}
Shift leader: James has a stomachache and asks for leave for half a day. Shift leader: Wang Lei asks for leave for two days. Shift leader: Chen Hua has returned to the students.