PHP String Exercises: Find the first character that is different between two strings
PHP String: Exercise-11 with Solution
Write a PHP script to find the first character that is different between two strings.
String1 : 'football'
String2 : 'footboll'
<?php $str1 = 'football'; $str2 = 'footboll'; $str_pos = strspn($str1 ^ $str2, "\0"); printf('First difference between two strings at position %d: "%s" vs "%s"', $str_pos, $str1[$str_pos], $str2[$str_pos]); printf("\n"); ?>
First difference between two strings at position 5: "a" vs "o"
PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?