<?php
function lowerCase($string){
$new_string = "";
$length = strlen($string);
for($i = 0; $i < $length; $i++){
if(ord($string[$i]) >= 65 && ord($string[$i]) <= 91){
$new_string .= chr(ord($string[$i]) + 32);
}else{
$new_string .= $string[$i];
}
}
return $new_string;
}
function is_anagram($string_one , $string_two){
$string_one = lowerCase($string_one);
$string_two = lowerCase($string_two);
$length_string_one = strlen($string_one);
$length_string_two = strlen($string_two);
$length = 0;
if ($length_string_one == $length_string_two){
for($i = 0; $i < $length_string_one; $i++){
for($k = 0; $k < $length_string_one; $k++){
if($string_one[$i] == $string_two[$k]){
$length += 1;
break;
}
}
}
if($length == $length_string_one){
return true;
}else{
return false;
}
}
}
echo is_anagram('bangladesh', 'eshbanglad');
function lowerCase($string){
$new_string = "";
$length = strlen($string);
for($i = 0; $i < $length; $i++){
if(ord($string[$i]) >= 65 && ord($string[$i]) <= 91){
$new_string .= chr(ord($string[$i]) + 32);
}else{
$new_string .= $string[$i];
}
}
return $new_string;
}
function is_anagram($string_one , $string_two){
$string_one = lowerCase($string_one);
$string_two = lowerCase($string_two);
$length_string_one = strlen($string_one);
$length_string_two = strlen($string_two);
$length = 0;
if ($length_string_one == $length_string_two){
for($i = 0; $i < $length_string_one; $i++){
for($k = 0; $k < $length_string_one; $k++){
if($string_one[$i] == $string_two[$k]){
$length += 1;
break;
}
}
}
if($length == $length_string_one){
return true;
}else{
return false;
}
}
}
echo is_anagram('bangladesh', 'eshbanglad');
No comments:
Post a Comment