php显示几个字符串,比较php中的两个字符串并显示字符差异

嗨,我正在努力做到这一点:

我想比较两个字符串并在php中计算他们的分数.

这意味着我有两个字符串:

$字符串1 = “例1”;

$字符串2 = “exumple22”;

现在我想比较字符串是否相等 – 在这种情况下它们不是.

但另外我想看到匹配的字符.至少算一算.

在这种情况下,将是:6;

我试过这个,但我卡住她的是我的榜样:

enter code here

include("connect.php");

$query="SELECT * FROM data where ID = '1'";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))

{

//echo "Score :{$row['scoreA']}
" ;

$scoretemp=$row['scoreA'];

$string1=$row['textA1'];

$string2=$row['textA2'];

}

mysql_close();

if (strcmp($string1, $string2) != 0){

echo "not equal in a case-sensitive string comparison
";

$j = strlen($string1);

for ($i = 0; $i < $j; $i++) {

$stringtemp1++;

echo $string1[$i].', ';

echo $stringtemp1;

}

$u = strlen($string2);

for ($t = 0; $t < $u; $t++) {

$stringtemp2++;

echo $string2[$t].', ';

echo $stringtemp2;

}$scoreA=($stringtemp1 - $stringtemp2);

$stringtemp1=0;$stringtemp2=0;

}

else{

echo "Stringmatch!
";

$e = strlen($string1);

for ($r = 0; $r < $e; $r++) {

$stringtemp1++;

echo $string1[$r].', ';

echo $stringtemp1;

}$scoreA=$stringtemp1;

$stringtemp1=0;

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值