当前位置:网站首页>php之相似文章标题similar_text()函数使用
php之相似文章标题similar_text()函数使用
2022-08-03 16:39:00 【reg183】
<?php
/** * similar_text()函数使用 * int similar_text ( string $first, string $second[, float $percent] ) */
$demo_title = "简明现代魔法";
$demo_arr_title = array("简单易懂的现代魔法", "简单明了的现代魔法", "简明扼要的古代魔法", "不简单的现代魔法", "很难懂的现代魔法");
$new_array = getSimilar($demo_title, $demo_arr_title);
echo "与[$demo_title]最相关的前三个文章是:<br/>";
// 选择相似的三篇文章
for ($j = 0; $j <= 2; $j++) {
echo ($j + 1) . ":" . $new_array[$j] . "<br/>";
}
//$title当前标题,$arrayTitle为需要查找的数组
function getSimilar($title, $arr_title)
{
$arr_len = count($arr_title);
for ($i = 0; $i <= ($arr_len - 1); $i++) {
//取得两个字符串相似的字节数
$arr_similar[$i] = similar_text($arr_title[$i], $title);
}
arsort($arr_similar); //按照相似的字节数由高到低排序
reset($arr_similar); //将指针移到数组的第一单元
$index = 0;
foreach ($arr_similar as $old_index => $similar) {
$new_title_array[$index] = $arr_title[$old_index];
$index++;
}
return $new_title_array;
}
边栏推荐
猜你喜欢
![[Unity Starter Plan] Making RubyAdventure01 - Player Creation & Movement](/img/e9/9bba4f7ecee81ae7ce7e492b54ee11.png)
[Unity Starter Plan] Making RubyAdventure01 - Player Creation & Movement

Hannah荣获第六季完美童模全球总决赛全球人气总冠军

2年开发经验去面试,吊打面试官,即将面试的程序员这些笔记建议复习

最强分布式锁工具:Redisson

Web3 安全风险令人生畏?应该如何应对?

C专家编程 第1章 C:穿越时空的迷雾 1.6 它很棒,但它符合标准吗

掌握Redis的Sentinel哨兵原理,可助你拿到25k的offer

TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践

如何使用MATLAB绘制极坐标堆叠柱状图

Understand the recommendation system in one article: Outline 02: The link of the recommendation system, from recalling rough sorting, to fine sorting, to rearranging, and finally showing the recommend
随机推荐
MATLAB | 一种简易的随机曼陀罗图形生成函数
J9数字虚拟论:元宇宙的潜力:一股推动社会进步的力量
ORACLE CLOUD 在国内有数据中心吗?
Description of the functional scenario of "collective storage and general governance" in the data center
DAYU200 OpenHarmony标准系统HDMI全屏显示
使用deepstream消息发送功能的时候,检测框没有检测标签,No text labels of bboxes displayed with osd for deepstream-test5
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
deepstresam的插件配置说明,通过配置osd,设置字体的背景为透明
【LeetCode】899. 有序队列
[redis] cache penetration and cache avalanche and cache breakdown solutions
error:Illegal instruction (core dumped),离线下载安装这个other版本numpy
socket快速理解
C专家编程 第1章 C:穿越时空的迷雾 1.10 “安静的改变”究竟有多少安静
WordPress建站技术笔记
Kubernetes 笔记 / 生产环境
机器人开发--Universal Scene Description(USD)
为何微博又双叒叕崩溃了?
leetcode:189. 轮转数组
面试不再被吊打!这才是Redis分布式锁的七种方案的正确打开方式
Selective Search学习笔记