Problems with PHP split string

Source: Internet
Author: User

In PHP, what if I want to split the string between the front and back of E?

Like this:
abcde1234 turn into ABCD 1234
Little white help ...

Reply content:

In PHP, what if I want to split the string between the front and back of E?

Like this:
abcde1234 turn into ABCD 1234
Little white help ...

Simple regular fix

$str = "abcde1234";
Preg_match ('/^ (\w+) e (\d+) $/i ', $str, $matches);

Print_r ($matches);

Array
(
[0] = abcde1234
[1] = ABCD
[2] = 1234
)

Explode () function http://www.w3school.com.cn/php/func_string_explode.asp


  
    abcd    [1] => 1234)

Online Demo: Http://3v4l.org/k7Dap

Support Upstairs, of course you can also use Strpos to find the location, and then use SUBSTR to cut out. You can read the manual for specific usage. Look what you think.

Regular expressions also allow for more complex segmentation

  • Related Article

    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.