PHP comparison of similar string methods _php tips

Source: Internet
Author: User
Tags string methods

The examples in this article describe how PHP compares similar strings. Share to everyone for your reference. The specific analysis is as follows:

This compares the similarity of two strings through the Similar_text function of PHP.

$word 2compare = "stupid";
$words = Array (
  ' stupid ', '
  Stu and PID ',
  ' hello ',
  ' foobar ',
  ' stpid ',
  ' upid ',
  ' Stuuupid ',
  ' sstuuupiiid ',
);
while (the list ($id, $str) = each ($words)) {
  Similar_text ($str, $word 2compare, $percent);
  print "Comparing ' $word 2compare ' with ' $str ':";
  Print round ($percent). "%\n";
}
/*
Results:
comparing ' stupid ' with ' stupid ': 100% comparing ' stupid ' with
' Stu and pid ': 71%
Comparing ' stupid ' with ' hello ': 0% comparing ' stupid ' and ' foobar ': 0% comparing ' stupid ' with ' stpid '
: 91%
  comparing ' stupid ' with ' upid ': 80%
comparing ' stupid ' and ' stuuupid ': 86% comparing ' stupid ' with ' sstuuup
IIId ': 71%
*

I hope this article will help you with your PHP program design.

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.