Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Created January 8, 2009 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipertracker/44767 to your computer and use it in GitHub Desktop.
Save hipertracker/44767 to your computer and use it in GitHub Desktop.
<?php
# What is more readible?
# version 1:
$args[] = '"'.mysql_escape_string(preg_replace("/^'(\d+)$/", '$1', $arg)).'"';
# version 2:
$a = ltrim($arg, "'");
if (is_numeric($a)) {
$arg = $a;
}
$args[] = '"'.mysql_escape_string($arg).'"';
# version 3:
if ($arg[0] == "'") {
$num = substr(1, $arg);
if (is_numeric($num)) {
$arg = $num;
}
}
$args[] = '"'.mysql_escape_string($arg).'"';
# version 4
$a = ltrim($arg, "'");
if (is_numeric($a)) {
$args[] = $a;
} else {
$args[] = '"'.mysql_escape_string($arg).'"';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment