Php intercepts Chinese characters

Source: Internet
Author: User
Php intercepts Chinese PHP strings

For example, Chengdu, Sichuan province
What I want to intercept is Sichuan province.
$ At = strpos ($ address, "province ");
$ Address = substr ($ address, 0, $ );
I don't know what went wrong. I didn't find a good article on the Internet for reference. I don't know which of the following experts can help me solve this problem.
It is mainly Chinese, and its length is different from that in English. I'm dizzy.
Who can give me a detailed answer and I will give 100 points. Thank you!


Reply to discussion (solution)

$ At = strpos ($ address, "province ");
$ Address = substr ($ address, 0, $ );
In this way, we can only intercept two words in Sichuan. I want Sichuan. when I am $ at + 1, there will be no value. I don't know why.

Calculate the length.

$ Address = 'Chengdu city, Sichuan province '; $ at = strpos ($ address, "province"); echo $ address = substr ($ address, 0, $ at + strlen ('Province '));
Sichuan


I didn't think of it. Thank you, moderator. Paste

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.