hi this is some basic code for a beginner to use comments suggestions welcome.
ROT13
PHP Code:
<?php
/**
* @author Ben Jones
* @name Rott13 Encoder/Decoder
* @version 1.0
* @license FreeForAll
*/
function crypt13($source)
{
for ($x = 0; $x < strlen($source); $x++) {
//Get char.
$c = $source[$x];
//Get byte.
$b = ord($source[$x]);
//Encrypt.
if (($c >= "A") and ($c <= "M") or ($c >= "a") and ($c <= "m")) {
$b += 13;
}
//Decrypt.
if (($c >= 'N') and ($c <= 'Z') or ($c >= 'n') and ($c <= 'z')) {
$b -= 13;
}
//Build the string.
$buf .= chr($b);
}
//Return result.
return $buf;
}
//Example.
$s = "Hello to all coders.";
$e = crypt13($s);
echo "Original: " . $s;
echo ("</br>");
echo "Encoded: " . $e;
echo ("</br>");
echo "Decoded: " . crypt13($e);
?>
Proper case
PHP Code:
<?php
/**
* @author Ben Jones
* @name ProperCase
* @version 1.0
*/
function ProperCase($source)
{
$source = strtolower($source);
//Break string into array.
$ary = explode(" ", $source);
for ($x = 0; $x <= sizeof($ary); $x++) {
$temp = $ary[$x];
//Build the string.
$line .= strtoupper($temp[0]) . substr($temp, 1) . " ";
}
return $line;
}
//Example
echo ProperCase("hello worLd this is a test string of title case.");
?>