PHP string segmentation and comparison _php techniques

Source: Internet
Author: User
Or use strcmp to judge, but this will tell you whether two strings are equal, but can't tell you where they are different.
My idea is to split a single string into letters (character) so that you can know exactly where the difference is.
Delimited string, use "Str_split" on it, syntax refer to "2". The result array is then output, and the advantage is that the space also acts as an element of the array. My previous example is because the previous string contains 2 spaces, and then one is only one. But the output is the same when you see the display.
You can also divide by other delimiters, such as "explode" or "preg_split", referring to "3" and "4". The former uses a simple split number, and the latter uses regular expressions. "Split" has been abolished (deprecated).
Another useful function is "str_word_count", which splits the string into arrays and clears both numbers and punctuation. If you want to count the frequency of words appearing, use "Array_count_values" and refer to "5".
Reference:
"1" http://us2.php.net/manual/en/language.operators.comparison.php
"2" Http://us2.php.net/manual/en/function.str-split.php1
"3" http://us2.php.net/manual/en/function.explode.php
"4" http://us2.php.net/manual/en/function.str-split.php
"5" http://us2.php.net/manual/en/function.array-count-values.php

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.