W3Schools.com

PHP similar_text() Function


PHP String Reference Complete PHP String Reference

Definition and Usage

The similar_text() function returns the number of matching characters of two strings.

It can also calculate the similarity of the two strings in percent.

Syntax

similar_text(string1,string2,percent)

Parameter Description
string1 Required. Specifies the first string to be compared
string2 Required. Specifies the second string to be compared
percent Optional. Specifies a variable name for storing the similarity in percent


Tips and Notes

Note: The levenshtein() function is faster than the similar_text() function. However, the similar_text() function will give you a more accurate result with less modifications needed.


Example 1

<?php
echo similar_text("Hello World","Hello Peter");
?>

The output of the code above will be:

7


Example 2

<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>

The output of the code above will be:

63.6363636364


PHP String Reference Complete PHP String Reference
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE