如何在阿拉伯语中使用类似的文本php代码 [英] how to use similar text php code in arabic

查看:38
本文介绍了如何在阿拉伯语中使用类似的文本php代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图将php similar_text()与阿拉伯语一起使用,但无法正常工作.但是,它适用于英语.

Trying to use php similar_text() with arabic, but it's not working. However it works great with english.

<?php 
$var = similar_text("ياسر","عمار","$per");
echo $var;
?>
outbot : 5 

那是错误的结果,应该为2.是否有带有阿拉伯字母的 similar_text()?

that's wrong result, it should be 2. Is there similar_text() with arabic letters?

推荐答案

由于阿拉伯文本是多字节字符串,因此无法使用常规的PHP函数(例如'similar_text()').

Because the Arabic text are multibyte strings normal PHP functions cannot be used (such as 'similar_text()').

echo(strlen("عمار"));

上面的代码输出:8

echo(mb_strlen("عمار", "UTF-8"));

使用指定了UTF-8编码的mb_strlen函数,输出为:4(正确的字符数).

Using the mb_strlen function with the UTF-8 encoding specified, the output is: 4 (the correct number of characters).

您可以使用mb_函数来创建自己的同类文本功能版本: http://php.net/manual/en/ref.mbstring.php

You can use the mb_ functions to make your own version of the similar_text function: http://php.net/manual/en/ref.mbstring.php

这篇关于如何在阿拉伯语中使用类似的文本php代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆