PHP string processing (extract letters)

Source: Internet
Author: User
PHP string processing (letter extraction) is like this. The student ID of the school is a mix of numbers and letters. The letter represents the system name.
For example, in 6SC14032S, SC is the Department of Science. what should I do if I want to extract the student IDs from the same department into an array. (The student ID is in the MYSQL database .)


Reply to discussion (solution)

First, extract the data from the database, then use regular expression matching to retrieve the middle letter, and press find letter component array.

What do you mean by removing the current student ID from the letter? Keep the number and store it in the array?

If this parameter is not excluded, find a letter. the student ID of the corresponding letter has an array.

What does the first 6 mean?

6 indicates that doctoral 5 is a graduate student.

Use substr to get by bit and then put it into an array.

$ N = '6sc14032s'; $ arr = array (); $ arr [] = substr ($ n, 0, 1); $ arr [] = substr ($ n, 1, 2 ); $ arr [] = substr ($ n, 3, 5); $ arr [] = substr ($ n, 8, 1); print_r ($ arr );

Select * from table where id like '% SC %'

First extract the data from the database, then use regular expression matching to retrieve the middle letter, and then group the data by letter into an array.

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.