This method masks credit card numbers and shows only the last 4 digits. I also forgot where I got this method from. If you wish to change the number of last digits shown, just modify the last parameter of the method. The part where it says $l = 4.

function maskCC($n, $b = 4, $p = 16, $m = 'X', $l = 4) {
  // $n = 'card number: 1234567890123456' string
  // $b = break into how many in each chunk?
  // $p = pad to what length?
  // $m = mask character?
  // $l = leave how many numbers showing?
  preg_match("/card number:\s*(\d+)[^\d]*/i", trim($n), $matches);
  $pattern = "/card number:\s*(\d+)/ie";
  $replacement = " implode('-', str_split( substr_replace( str_pad('$1', '$p', '0', STR_PAD_LEFT), str_repeat('$m', $p-$l), 0, $l * -1 ), $b) ); ";
  return preg_replace($pattern, $replacement, trim($n));
}

// use the function
var_dump(maskCC("\ncard number: 1222233334444\n"));

Here are two methods to encrypt and decrypt using Base64. I forgot where I got this from but these 2 methods are pretty handy. Make sure you remember your key as your string will be encrypted and decrypted according to what you specify as key. Key is a string here.

Usage is as follows:
$encrypted = encrypt("to encrypt string", "chitgoks");
$decrypted = decrypt($encrypted, "chitgoks");

$decrypted will return to encrypt string.

function encrypt($string, $key) {
  $result = '';
  for($i=0; $i<strlen($string); $i++) {
    $char = substr($string, $i, 1);
    $keychar = substr($key, ($i % strlen($key))-1, 1);
    $char = chr(ord($char)+ord($keychar));
    $result.=$char;
  }

  return base64_encode($result);
}

function decrypt($string, $key) {
  $result = '';
  $string = base64_decode($string);

  for($i=0; $i<strlen($string); $i++) {
    $char = substr($string, $i, 1);
    $keychar = substr($key, ($i % strlen($key))-1, 1);
    $char = chr(ord($char)-ord($keychar));
    $result.=$char;
  }

  return $result;
}

Deletes a directory in the server’s file system.

function deleteDirectory($dir, $DeleteMe) {
  if(!$dh = @opendir($dir)) return;
  while (false !== ($obj = readdir($dh))) {
    if($obj=='.' || $obj=='..') continue;
    if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
  }
  closedir($dh);
  if ($DeleteMe){
  @rmdir($dir);
}

Related Posts Plugin for WordPress, Blogger...