Question about chinese character filtering in php

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

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.