Q:

Write a PHP script to find the first character that is different between two strings

0

Write a PHP script to find the first character that is different between two strings.

String1 : 'football'
String2 : 'footboll'

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?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");
?>

Sample Output:

First difference between two strings at position 5: "a" vs "o"

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now