Question about string splitting in PHP

Source: Internet
Author: User
In php, what if I want to split the strings before and after e? Like this: abcde1234 is converted to abcd1234. in php, what should I do if I want to split the strings before and after e?

Like this:
Abcde1234 to abcd 1234
Tom for help...

Reply content: in php, what should I do if I want to split the strings before and after e?

Like this:
Abcde1234 to abcd 1234
Tom for help...

Simple Regular Expression

$ 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. You can also use strpos to find the location and use substr to crop it. For detailed usage, see the manual. Let's see what you think.

Regular Expressions can also achieve more complex segmentation.

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.