- var_dump: documentation ( source)
- str_replace: documentation ( source)
- array_diff: documentation ( source)
- str_split: documentation ( source)
<?php
$name1 = 'The cat is red and wet';
$name2 = 'The cat is green and wet';
function stringDiff($string1, $string2)
{
$x = str_split($string1);
$y = str_split($string2);
$diff = array_diff($x, $y);
foreach ($diff as $letter) {
$string1 = str_replace($letter, '-', $string1);
}
return $string1;
}
var_dump(stringDiff($name1, $name2));