About the character addition method

Source: Internet
Author: User
The character intersection method currently has two strings: "A & nbsp; B & nbsp; C" "D & nbsp; E & nbsp; F" to determine whether the total character of A string has an intersection, I wrote a method myself and thought it was a bit complicated. I converted the character into an array for comparison. Is there a direct comparison function? Second, the characters are separated by spaces. if there is no space, is there any faster way to convert the string into an array. Character intersection method
There are currently 2 strings
"A B C"
"D e f"
I have written a method to determine whether there is an intersection of the total characters of a string. I think it is a bit complicated. I want to convert the character into an array for comparison. Is there a direct comparison function? Second, the characters are separated by spaces. if there is no space, is there any faster way to convert the string into an array ..


$ Str_a = "a B C ";
$ Str_ B = "D E F ";
$ R = array_intersect (explode ("", $ str_a), explode ("", $ str_ B ));
Echo! Empty ($ R )? "Intersection": "No intersection ";

------ Solution --------------------
Spaces are also characters. why not?

No space
$ Str_a = "ABC ";
$ Str_ B = "DEF ";
Echo (similar_text ($ str_a, $ str_ B )? 'You': 'none'). 'intersection'; // no intersection

$ Str_a = "ABC ";
$ Str_ B = "DEB ";
Echo (similar_text ($ str_a, $ str_ B )? 'You': 'none'). 'interse'; // intersection

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.