Skip to content

Instantly share code, notes, and snippets.

@alganet
Created March 31, 2011 15:12
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 alganet/896534 to your computer and use it in GitHub Desktop.
Save alganet/896534 to your computer and use it in GitHub Desktop.
Very, very very simple SQL formatter.
<?php
function formatSql($sql)
{
return preg_replace(
'/(select|from|(inner|left) join|where|limit|update|set|insert|values)/i',
"\n$1\n ",
str_replace("\n", '', $sql)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment