Skip to content

Instantly share code, notes, and snippets.

@nightsh
Created April 16, 2013 14:24
Show Gist options
  • Save nightsh/5396310 to your computer and use it in GitHub Desktop.
Save nightsh/5396310 to your computer and use it in GitHub Desktop.
uglify_query - a function to remove unneded spacing out of SQL queries
<?php
/** uglify_query - a function to remove unneded spacing out of SQL queries
*
* This is a very basic function that can be used both in OOP and non-OOP
* environments, transforming an SQL query that was formatted for readibility
* into a short, one-liner, single-spaced query that won't produce a nasty log
* pollution and line noise.
*
* @param string $query The pretty formatted query, with tabs, newlines etc.
* @return string The query, stripped of all extra spaces, tabs and newlines
*
*/
function uglify_query( $query ) {
return preg_replace('/[ \t]+/', ' ', preg_replace('/[\r\n]+/', " ", $query));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment