function checkCircularpalindrome($string)
{
    $l = strlen($string);
    $str3 = $string;
    for ($i = 0; $i < $l; $i++) {
        $str1 = substr($str3, $i + 1, $l - $i - 1);
        $str2 = substr($str3, 0, $i + 1);
        $str = $str1 . $str2;
        if (checkPalindrome($str)) {
            return true;
        }
    }
    return false;
}
            <input type="radio" name="choice" value="hash" id="hash" />
            <label for="hash">Hash String</label>

            <input type="radio" name="choice" value="shuffle" id="shuffle" />
            <label for="shuffle">Shuffle String</label>

            <input type="submit" value="Submit" />
        </form>

        <?php 
if (isset($_GET['input']) && isset($_GET['choice'])) {
    $input = $_GET['input'];
    $choice = htmlspecialchars($_GET['choice']);
    switch ($choice) {
        case 'palindrome':
            checkPalindrome($input);
            break;
        case 'reverse':
            echo strrev($input);
            break;
        case 'split':
            splitString($input);
            break;
        case 'hash':
            echo hash('md5', $input);
            break;
        case 'shuffle':
            echo str_shuffle($input);
            break;
        default:
            echo 'Invalid choice';
    <label for="split">Split</label>
    <input type="radio" id="hash" name="modifier" value="hash"/>
    <label for="hash">Hash String</label>
    <input type="radio" id="shuffle" name="modifier" value="shuffle"/>
    <label for="shuffle">Shuffle String</label>
    <input type="submit" name='submit'/>
</form>
</body>
</html>

<?php 
if (isset($_GET['input']) && isset($_GET['submit'])) {
    $choice = $_GET['modifier'];
    switch ($choice) {
        case 'palindrome':
            echo checkPalindrome($_GET['input']);
            break;
        case 'reverse':
            echo strrev($_GET['input']);
            break;
        case 'split':
            echo splitStr($_GET['input']);
            break;
        case 'hash':
            echo hashStr($_GET['input']);
            break;
        case 'shuffle':
            echo str_shuffle($_GET['input']);
            break;
    }
}
Beispiel #4
0
    <label for="hash">Hash String</label>
    <input type="radio" name="option" id="shuffle" value="shuffle"/>
    <label for="shuffle">Shuffle String</label>
    <input type="submit"/>
</form>
<?php 
if (isset($_POST['input']) && isset($_POST['option'])) {
    $input = $_POST['input'];
    $operation = $_POST['option'];
    function checkPalindrome($string)
    {
        $initialString = strtolower(preg_replace("/[^A-Za-z0-9]/", "", $string));
        return $initialString === strrev($initialString);
    }
    if ($operation === 'palindrome') {
        $isPalindrome = checkPalindrome($input);
        if ($isPalindrome === true) {
            echo "{$input} is a palindrome!";
        } else {
            echo "{$input} is not a palindrome!";
        }
    }
    if ($operation === 'reverse') {
        echo strrev($input);
    }
    if ($operation === 'split') {
        $input = str_split($input);
        $result = implode(' ', $input);
        echo $result;
    }
    if ($operation === 'hash') {
 * @param string $string
 * @return string
 */
function checkPalindrome($string)
{
    $lowerStr = strtolower($string);
    $revString = strrev($lowerStr);
    if ($revString === $lowerStr) {
        return "\"{$string}\" is a Palindrome.";
    } else {
        return "\"{$string}\" is not a Palindrome.";
    }
}
echo checkPalindrome("racecar");
echo "<br />";
echo checkPalindrome("racecarrrrr");
?>
                </p>
            </div>
            
            <div>
                <h1>
                    5. Write some simple code that demonstrates the difference 
                    between the == and === comparison operators
                </h1>
                <hr />
                <p>
                    <?php 
$a = 4;
$b = "4";
if ($a == $b) {
            <input type="radio" name="action" id="split" value="split" />
            <label for="split">Slpit</label>
            <input type="radio" name="action" id="hash" value="hash" />
            <label for="hash">Hash String</label>
            <input type="radio" name="action" id="shuffle" value="shuffle" />
            <label for="shuffle">Shuffle String</label>
            <input type="submit" />
        </form><br />
        
        <?php 
if (isset($_POST['string'], $_POST['action'])) {
    $inputStr = $_POST['string'];
    $action = $_POST['action'];
    switch ($action) {
        case 'palindrome':
            $isPalindrome = checkPalindrome($inputStr);
            if ($isPalindrome) {
                echo htmlspecialchars($inputStr) . " is palindrome!";
            } else {
                echo htmlspecialchars($inputStr) . " is NOT palindrome!";
            }
            break;
        case 'reverse':
            echo htmlspecialchars(strrev($inputStr));
            break;
        case 'split':
            $inputStr = str_split($inputStr, 1);
            $inputStr = implode(' ', $inputStr);
            echo htmlspecialchars($inputStr);
            break;
        case 'hash':