コード例 #1
0
<?php

$requestTransformed = "";
if (!empty($_GET['value'])) {
    $request = $_GET['value'];
    $lastChar = substr($request, -1);
    $lastCharTransformed = isUpperCase($lastChar) ? strtolower($lastChar) : strtoupper($lastChar);
    $requestTransformed = $lastCharTransformed;
} else {
    $requestTransformed = "NoValue!";
}
function isUpperCase($char)
{
    $upper = strtoupper($char);
    return $upper === $char;
}
echo $requestTransformed;
//$s = ($s == strtolower($s)) ? strtoupper($s) : strtolower($s);
コード例 #2
0
function IsStringLowerCase($string)
{
    $lower = TRUE;
    $cnt = count($string);
    for ($x = 0; $x < $cnt; $x++) {
        if (isUpperCase($string[$x])) {
            $lower = FALSE;
            break;
        }
    }
    return $lower;
}
コード例 #3
0
<?php

$inputString = $_GET["text"];
//$wordArr = preg_split("/[\s\W\d]+/", $inputString, -1, PREG_SPLIT_NO_EMPTY);
$str = $inputString;
$resultStr = '';
$word = "";
while (strlen($str) > 0) {
    preg_match('/([a-zA-Z]+)|([\\s\\W\\d]*)/', $str, $match);
    $word = $match[1];
    $separator = $match[2];
    $count = strlen($word);
    $word = isUpperCase($word);
    $resultStr .= $word . $separator;
    $count += strlen($separator);
    $str = substr($str, $count, strlen($inputString));
}
echo "<p>" . htmlspecialchars($resultStr) . "</p>";
function isUpperCase($word)
{
    if (strtoupper($word) == $word) {
        $word = strrev($word);
        if (getPalindrome($word)) {
            $doubleCharWord = '';
            for ($i = 0; $i < strlen($word); $i++) {
                $currentChar = $word[$i];
                $doubleCharWord .= $currentChar . $currentChar;
            }
            return $doubleCharWord;
        }
    }