Created
January 23, 2017 01:19
-
-
Save jsiesquen/f3fcdc424c85f32be695d74fdaca10e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/html; charset=ISO-8859-1'); | |
/** | |
* Class for convert letters from an input string | |
* Restrictions: | |
* - Work with latin alfhabet, except tilde letters. | |
* - No depend of setting of "Regional Configuration". | |
* Execution using: | |
* - From Console: | |
* # php ChangeString.php "<argument string>" | |
* Note: previouly replace at line 90 by: | |
* echo $cs->build(); | |
* - From Code Inside, instance from Class: | |
* $cs = new ChangeString(); | |
* echo $cs->build('Juan Siesquen Rosales'); | |
* - From Browser: | |
* http://localhost/ChangeString.php?anyvar=your-string-to-Test | |
* Note: previouly replace at line 90 by: | |
* echo $cs->build(); | |
*/ | |
class ChangeString | |
{ | |
var $argCount = 0; | |
var $argVals = null; | |
var $stringOrg = ''; | |
var $lettersRange = array(); | |
var $allLetters = array(); | |
var $convLetters = array(); | |
function __construct() | |
{ | |
if (isset($_SERVER['QUERY_STRING'])) { | |
$arrGetString = explode("&", htmlentities($_SERVER['QUERY_STRING'])); | |
if (strpos($arrGetString[0], '=') !== false) | |
$this->stringOrg = explode("=", $arrGetString[0])[1]; | |
} else { | |
$this->argCount = isset($argc) ? $argc:(int)$_SERVER['argc']; | |
$this->argVals = isset($argv) ? $argv:$_SERVER['argv']; | |
$arrGetString = array(); | |
$this->stringOrg = isset($this->argVals[1]) ? $this->argVals[1] : ''; | |
} | |
$this->replacers(); | |
} | |
function replacers() | |
{ | |
/* letters range */ | |
$this->lettersRange = array_merge( | |
(array)array_slice(range('A', 'N'), 1), | |
array(chr(ord('Ñ'))), | |
range('O', 'Z'), array('A'), | |
(array)array_slice(range('a', 'n'), 1), | |
array(chr(ord('ñ'))), | |
range('o', 'z'), array('a') | |
); | |
/* letters range */ | |
/* letters to replace */ | |
$this->allLetters = array_merge( | |
range('A', 'N'), array(chr(ord('Ñ'))), | |
range('O', 'Z'), | |
range('a', 'n'), array(chr(ord('ñ'))), | |
range('o', 'z') | |
); | |
foreach ($this->allLetters as $k => $v) { | |
$this->convLetters[$v] = $this->lettersRange[$k]; | |
} | |
/* all letters */ | |
} | |
/** | |
* Update each letter within of an inputString | |
*/ | |
function build($inputString = null) | |
{ | |
$evaluateString = null; | |
if ($inputString === null) | |
$evaluateString = $this->stringOrg; | |
else | |
$evaluateString = $inputString; | |
return "Input String:\n" . $evaluateString . ";\n\n" . | |
"Result:\n" . strtr($evaluateString, $this->convLetters); | |
} | |
} | |
$cs = new ChangeString(); | |
echo $cs->build('**Casa 52Z'); // InputString Example | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment