小编use*_*883的帖子

比较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']} <br>" ;
    $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 <br>";
$j = strlen($string1);
    for ($i = 0; $i < $j; $i++) {
    $stringtemp1++;
    echo $string1[$i].', ';
    echo $stringtemp1;
    } …
Run Code Online (Sandbox Code Playgroud)

php string compare character match

8
推荐指数
3
解决办法
1万
查看次数

标签 统计

character ×1

compare ×1

match ×1

php ×1

string ×1