Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Albert Peschar http://www.cheatguide.nl/

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Remove magic quotes on GPC data

Removes magic quotes on $_GET, $_POST, $_COOKIE, $_FILES and $_REQUEST, when they are enabled.

<?php

// remove magic_quotes
if(get_magic_quotes_gpc())
{
  function undo_magic_quotes_array($array)
  {
    return is_array($array) ? array_map('undo_magic_quotes_array', $array) : str_replace("\\'", "'",
							                                                               str_replace("\\\"", "\"",
                                                                             str_replace("\\\\", "\\",
                                                                             str_replace("\\\x00", "\x00", $array))));
  }

  $_GET = undo_magic_quotes_array($_GET);
  $_POST = undo_magic_quotes_array($_POST);
  $_COOKIE = undo_magic_quotes_array($_COOKIE);
  $_FILES = undo_magic_quotes_array($_FILES);
  $_REQUEST = undo_magic_quotes_array($_REQUEST);
}

?>

Remove magic quotes on GPC data

Removes magic quotes on $_GET, $_POST, $_COOKIE, $_FILES and $_REQUEST, when they are enabled.

<?php

// remove magic_quotes
if(get_magic_quotes_gpc())
{
  function undo_magic_quotes_array($array)
  {
    return is_array($array) ? array_map('undo_magic_quotes_array', $array) : str_replace("\\'", "'",
							                                                               str_replace("\\\"", "\"",
                                                                             str_replace("\\\\", "\\",
                                                                             str_replace("\\\x00", "\x00", $array))));
  }

  $_GET = undo_magic_quotes_array($_GET);
  $_POST = undo_magic_quotes_array($_POST);
  $_COOKIE = undo_magic_quotes_array($_COOKIE);
  $_FILES = undo_magic_quotes_array($_FILES);
  $_REQUEST = undo_magic_quotes_array($_REQUEST);
}

?>

Zeropad a number

Pads a string with 0's until the given length limit is met

<?php
function zeropad($number, $limit) {
  return (strlen($number) >= $limit) ? $number : zeropad("0" . $number, $limit);
}
?>
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS