Teacher: Has Xiao Ming arrived yet? Monitor: Xiao Ming has a stomachache and a half day's leave. Teacher: What did Wang Lei do? Monitor: Wang Lei please leave for 2 days. Teacher: Chen Hua didn't come? Monitor: Chen Hua to the students to go back.
I want to filter out the teacher's questions. Only left: Squad Leader: Xiao Ming belly pain, leave half a day. Monitor: Wang Lei please leave for 2 days. Monitor: Chen Hua to the students to go back.
So how to write PHP code.
Reply to discussion (solution)
1. The. End Form Array
2. The loop array will start with the "teacher" regular replacement to empty
3. Exporting Array contents
The teacher's question is not all the end of the period,
I don't know formal list, can you give me the code?
Can be at the end of the monitor this is always there, can be re-output when added
If it's a question like what you're doing right now, you can just do the array merge after you cut it by the period.
$s = ' Teacher: Has Xiao Ming arrived yet? Monitor: Xiao Ming has a stomachache and a half day's leave. Teacher: What did Wang Lei do? Monitor: Wang Lei please leave for 2 days. Teacher: Chen Hua didn't come? Monitor: Chen Hua to the students to go back. '; Echo preg_replace ('/teacher:. + (monitor. +)/U ', ' $ ', $s);
Monitor: Xiao Ming has a stomachache and a half day's leave. Monitor: Wang Lei please leave for 2 days. Monitor: Chen Hua to the students to go back.
$str = ' Teacher: Has Xiao Ming arrived yet? Monitor: Xiao Ming has a stomachache and a half day's leave. Teacher: What did Wang Lei do? Monitor: Wang Lei please leave for 2 days. Teacher: Chen Hua didn't come? Monitor: Chen Hua to the students to go back. $arr =explode (' Teacher: ', $str); foreach ($arr as $k + $v) {$item =mb_strpos ($v, ' class ', 0, ' GBK '); $len =mb_strlen ($v, ' GBK '); $res =mb_substr ($v, $item, $len, ' GBK '); echo $res;}
Monitor: Xiao Ming has a stomachache and a half day's leave. Monitor: Wang Lei please leave for 2 days. Monitor: Chen Hua to the students to go back.