Introduction to PHP string segmentation and comparison

Source: Internet
Author: User
The most common way to compare the equality of two strings is to use "= = =" To determine the difference between it and "= =", in short, the former emphasizes the "identical" type also requires the same, the latter requires "Equal", the value of the same can be.

Or use strcmp to judge, but this can tell you whether the two strings are equal, but can't tell you where the difference is.
My idea is that a single string is divided into letters (character) so that comparisons can be made to know exactly where they are.
Delimited string, using "Str_split" on it, Syntax reference "2". Then output an array of results, the advantage is that even a space will be an element of the array. My previous example is because the previous string contains 2 spaces, and the second one is only one. But the output will see the same display.
You can also split by other separators, such as "explode" or "preg_split", referring to "3" and "4". The former uses a simple split number, which uses regular expressions. "Split" has been abolished (deprecated).
Another useful function is "str_word_count", which splits the string into arrays and clears the numbers and punctuation marks. If you want to count how often words appear, you can use "array_count_values",

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.