Categories
PHP

Palindrome in php

What is Palindrome?

A palindrome is a word, phrase, number, or sequence of characters which reads the same in either direction. The words A and I are the simplest and smallest palindromes. Few of the most commonly used are :-
RACECAR LEVEL CIVIC POP MADAM EYE NUN RADAR

The word palindrome is derived from the Greek palíndromos, meaning running back again (palín = AGAIN + drom–, drameîn = RUN).

Words like LIVE and STRAW (which read EVIL and WARTS backwards) are not themselves palindromes but the phrases LIVE EVIL and STRAW WARTS are. A palindrome is not necessarily a single word.

While creating palindrome, it is usually accepted that punctuation and word spacings are ignored, and so the famous MADAM, I’M ADAM is a valid palindrome.

Here are a few good ones:

    Do geese see God?
    Murder for a jar of red rum.
    Some men interpret nine memos.
    Never odd or even.

palindrome
A famous palindrome “Able was I ere I saw Elba” purportedly spoken by Napoleon, referring to his first sighting of Elba, the island where the British exiled him.

How to verify a word is palindrome ?

Find given string is palindrome or not in PHP using native strrev() function

<?php
$word = 'madam';  // declare a varibale
echo 'String: <b>' . $word . '</b>';
$reverse = strrev($word); // reverse the word
if ($word == $reverse) // compare if the original word is same as the reverse of it
    echo ' is a palindrome';
else
    echo ' is not a palindrome';
?>

Find given string is palindrome or not in PHP without using strrev() function

<?php
$mystring = 'madam'; // set the string
echo 'String: <b>' . $mystring . '</b>';

$myArray = array(); // initialize an array
$myArray = str_split($mystring); //split into array
$len = sizeof($myArray); // get the size of array
$newString = '';

for ( $i = $len; $i >= 0; $i-- ) {
    $newString .= $myArray[$i];
}

if ( $mystring == $newString ) {
    echo ' is a palindrome';
} else {
    echo ' is not a palindrome';
}
?>
'Coz sharing is caring
Categories
linux PHP

How to Enable and disable phpinfo()

The phpinfo() function is mostly disabled in the shared hosting service due to security reasons. phpinfo()is disabled, as it displays information which can be used to compromise the server. By disabling the phpinfo() one can take a step to secure the server, but it becomes difficult for debugging.

phpinfo()
phpinfo()

Here are steps for enabling and disabling the phpinfo() :-

You want to enable phpinfo

Considering you have access to the server’s php.ini file then edit this file in any editor e.g. vim. Search and change the disable_functions directive from disable_functions = phpinfo to disable_functions =

Considering you don’t have access to your server’s php.ini file (most likely case), you may be able to create your own php.ini file. And change the disable_functions directive that way in your own version of php.ini. If that doesn’t work, learn “How to debug php application with phpinfo() disabled ?

You want to disable phpinfo

Considering you have access to the server’s php.ini file, then change the line that includes the disable_functions directive so that it says disable_functions = phpinfo

Considering you don’t have access to your server’s php.ini file, you may be able to create your own php.ini file and change the disable_functions directive that way. Or, add a line in the application that says

ini_set('disable_functions', 'phpinfo');
'Coz sharing is caring