About the character cross method

Source: Internet
Author: User
About character intersection methods
There are currently 2 strings
"A B C"
"D E F"
Judging the total character of the string whether there is a intersection, I wrote a method, I feel a bit complicated, is the character to the array comparison, there is no direct comparison of the function? Second, the characters are separated by a space, if there is no space, there is no 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)? " There is intersection ":" No intersection ";

------Solution--------------------
The space is also the character, why not count?

When there is no space
$str _a = "ABC";
$str _b = "DEF";
Echo (Similar_text ($str _a, $str _b)? ' Have ': ' None '). ' Intersection '; No intersection

$str _a = "ABC";
$str _b = "DEB";
Echo (Similar_text ($str _a, $str _b)? ' Have ': ' None '). ' Intersection '; have 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.