note 94775 deleted from function.strcmp by danbrown
| From: | danbrown@php.net | Date: | Tue, 24 Nov 2009 16:08:29 +0000 |
| Subject: | note 94775 deleted from function.strcmp by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163234@lists.php.net to get a copy of this message | ||
Note Submitter: Marcin Szychowski
----
You may find this useful:
<?php
function vistrcmp($s1, $s2){
if(strlen($s2)>strlen($s1)){
$t=$s1;$s1=$s2;$s2=$t;
}
for($i=0;$i<strlen($s2);$i++){
if($s1[$i]!=$s2[$i])$ret.='.';
else $ret.=' ';
}
$ret.=str_repeat('/', strlen($s1)-strlen($s2));
return $ret;
}
$old = 'My old string';
$new = 'My new string number two';
$diff = mystrcmp($old, $new);
printf("<pre>OLD: %s\nNEW: %s\nDIFF:%s\n</pre>", $old, $new, $diff);
/* Should show:
OLD: My old string
NEW: My new string number two
DIFF: ... ///////////
*/
?>