Problems with PHP filtering Chinese characters

Source: Internet
Author: User
Tags ming
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.
  • 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.