This program should return an array of two strings as output but NOT present in str2
Write a PHP program which takes two strings as input from the user (str1 and str2).<br>
This program should return an array of two strings as output (op1 and op2).<br>
op1 should contain all the characters which are present in str1 but NOT present in str2.<br>
op2 should contain all the characters which are present in str2 but NOT present in str1.
Example1:
Input1 : ABC
Input2 : BC
Outpt = A
Example2:
Input1 : BC
Input2 : BANGALORE
Outpt = C
Answer:
<?php
//BC BANGALORE = C
//ABC BC = A
//processStrings('BC','BANGALORE');
processStrings('ABC','BC');
function processStrings($str1, $str2) {
//echo strlen($str2);
$finalString = '';
for($i=0; $i<strlen($str1); $i++){
//echo "=".$str1[$i];
//Logic start
$jay1 = $str2;
$jay2 = $str1[$i];
if (strpos($jay1,$jay2) !== false) {
//echo "n $jay1 contains $jay2";
}else{
$finalString.=$jay2;
}
//logic close
}//for close
echo "n Result=".$finalString;
}
?>
Share on Facebook
Fatal error: Uncaught mysqli_sql_exception: MySQL server has gone away in /Applications/MAMP/htdocs/bharatbaba.com/classCommon.php:71
Stack trace:
#0 /Applications/MAMP/htdocs/bharatbaba.com/classCommon.php(71): mysqli_query(Object(mysqli), 'INSERT INTO ips...')
#1 /Applications/MAMP/htdocs/bharatbaba.com/analytics.jay.php(53): common::sql_queryNewVerson('INSERT INTO ips...', Object(mysqli))
#2 /Applications/MAMP/htdocs/bharatbaba.com/footer.php(76): require_once('/Applications/M...')
#3 /Applications/MAMP/htdocs/bharatbaba.com/blog.php(120): require_once('/Applications/M...')
#4 {main}
thrown in
/Applications/MAMP/htdocs/bharatbaba.com/classCommon.php on line
71