


Use PHP similar text to calculate the similarity of two strings, similartext_PHP tutorial
Use PHP similar text to calculate the similarity of two strings, similartext
In website development, we often use php similar text to calculate the similarity of two strings;
1, usage of similar_text
If I want to calculate the similarity between "ly89cn" and "ly89", there are two ways to express it
Copy code The code is as follows:
echo similar_text('ly89cn', 'ly89');
This outputs 4 because they have 4 equal characters
Copy code The code is as follows:
similar_text('ly89cn', 'ly89', $percent);
echo $percent;
This outputs 80, $percent represents the percentage, indicating that they are 80% similar
Of course, you can also compare two Chinese characters, such as "Wang Yelou's personal blog" and "Wang Yelou"
Copy code The code is as follows:
echo similar_text('Wang Yelou's personal blog', 'Wang Yelou');
Output 9 like this, indicating that their 9 bytes are equal
Copy code The code is as follows:
similar_text('Wang Yelou's personal blog', 'Wang Yelou', $percent);
echo $percent;
Output 54.545454545455, please note that Chinese characters may not be accurate!
PHP similar_text() function
Example
Calculate the similarity between two strings and return the number of matching characters:
Copy code The code is as follows:
echo similar_text("Hello World","Hello Shanghai");
?>
Running instance
Definition and usage
The similar_text() function calculates the similarity of two strings.
This function can also calculate the percentage similarity of two strings.
Note: levenshtein() function is faster than similar_text() function. However, the similar_text() function provides more accurate results with fewer modifications required.
Grammar
Copy code The code is as follows:
similar_text(string1,string2,percent)
Parameters | Description |
---|---|
string1 | Required. Specifies the first string to compare. |
string2 | Required. Specifies the second string to be compared. |
percent | Optional.规定供存储百分比相似度的变量名。 |
技术细节
返回值:
|
返回两个字符串的匹配字符的数目。
|
||||
PHP 版本: | 4
更多实例
例子 1
similar_text("Hello World","Hello Shanghai",$percent); echo $percent. "%"; ?> http://www.bkjia.com/PHPjc/1068822.htmlwww.bkjia.comtrue http://www.bkjia.com/PHPjc/1068822.htmlTechArticle 使用PHP similar text计算两个字符串相似度,similartext 在网站开发中,我们经常使用php similar text 计算两个字符串相似度; 1,similar_text的用法 如...
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
