Write a PHP program to test if a given string occurs at the end of another given string.
<?php function str2_in_str1($str1, $str2) { $p_len = strlen($str2); $w_len = strlen($str1); $w_start = $w_len-$p_len-1; if (substr($str1, $w_len-$p_len, $p_len) == $str2) { return "true"; } else { return "false"; } } echo str2_in_str1("Python","on")."\n"; echo str2_in_str1("JavaScript","php")."\n"; ?>
Sample Output:
true false
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer