<?php
function isPalindrome($s) {
//s = "A man, a plan, a canal: Panama"
$s= strtolower($s);
$filtered = "";
$len = strlen($s);
for ($i= 0; $i<$len; $i++){
$ascii = ord($s[$i]);
if (($ascii>=97 && $ascii<123) ||
($ascii>47 && $ascii<58)){
$filtered.=$s[$i];
}
}
return $filtered == strrev($filtered);
}
$s = "A man, a plan, a canal: Panama";
echo isPalindrome($s);
<?php
function space($sentence) {
$sentence= trim($sentence); //trim function-Breaks a sentence after spaces.
//str_contains-Checks if there is a blank in this sentence in this situation.
while (str_contains($sentence, ' ')) {
// str_replace-Replaces the first element with the second element in this sentence.
$sentence= str_replace(' ', ' ',$sentence);
}
return $sentence;
}
$sentence " hi i am gvanca";
echo space($sentence);
<?php
function gettingmarried($women, $men) {
$count=count($women); //count-counts the number of women.
// '!=' -If not equal.
if ($women != count($men)) {
echo "I don't have all pairs";
}
//array_combine-Pairs the data of the first element with the second.
return array_combine($women, $men);
}
print_r(gettingmarried(["elene","mariami"], ["dato", "vano"]));
function isSpecialArray($str) {
$length = strlen($str);
$count=1;
for ($i=1; $i<$length; $i++) {
if ($str[0]="#") {
► // 0123456789abcdefABCDEF
if ((ord($str[$i]) > 64 && ord($str[$i]) < 71) || (ord($str[$i]) > 47 &&
ord($str[$i]) < 58) || (ord($str[$i]) > 96 && ord($str[$i]) < 103)) {
$count+=1;
}
}
}
if (strlen($str)==7 && $count==$length){
return true;
}
return false;
}
var_dump(isSpecialArray("#CD5C5B"));
`semicolon.
// Example #1 eval()
$string = 'cup';
$string2= 'coffee';
$str = 'This is a $string with $string2 in it.';
echo $str. "\n"; // outputs: This is a $string with $string2 in it.
eval("\$str = \"$str\";");
echo $str. "\n"; // outputs: This is a cup with coffee in it.
► Let's make another simple example for better understanding.
Put a mathematical operation in a string. obviously PHP can't solve example
in case of putting it in a string.◄
$operation = "20 - 5";
echo $operation; // outputs 20 - 5
echo eval( $operation. ';' ); // it doesn't show anything.
echo eval( 'echo '. $operation. ';' ); // outputs 15
// or
eval( '$temp = ' .$operation. ';' );
echo $temp; // outputs 15