note 51618 modified in function.str-ireplace by aidan

From: Date: Sun, 24 Jul 2005 04:18:15 +0000
Subject: note 51618 modified in function.str-ireplace by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-92367@lists.php.net to get a copy of this message
here's a neat little function I whipped up to do HTML color coding of SQL strings. <?php /** * Output the HTML debugging string in color coded glory for a sql query * This is very nice for being able to see many SQL queries * @access public * @return void. prints HTML color coded string of the input $query. * @param string $query The SQL query to be executed. * @author Daevid Vincent [daevid@LockdownNetworks.com] * @version 1.0 * @date 04/05/05 * @todo highlight SQL functions. */ function SQL_DEBUG( $query ) { if( $query == '' ) return 0; global $SQL_INT; if( !isset($SQL_INT) ) $SQL_INT = 0; //[dv] this has to come first or you will have goofy results later. $query = preg_replace("/['\"]([^'\"]*)['\"]/i", "'<FONT COLOR='#FF6600'>$1</FONT>'", $query, -1); $query = str_ireplace( array ( '*', 'SELECT ', 'UPDATE ', 'DELETE ', 'INSERT ', 'INTO', 'VALUES', 'FROM', 'LEFT', 'JOIN', 'WHERE', 'LIMIT', 'ORDER BY', 'AND', 'OR ', //[dv] note the space. otherwise you match to 'COLOR' ;-) 'DESC', 'ASC', 'ON ' ), array ( "<FONT COLOR='#FF6600'><B>*</B></FONT>", "<FONT COLOR='#00AA00'><B>SELECT</B> </FONT>", "<FONT COLOR='#00AA00'><B>UPDATE</B> </FONT>", "<FONT COLOR='#00AA00'><B>DELETE</B> </FONT>", "<FONT COLOR='#00AA00'><B>INSERT</B> </FONT>", "<FONT COLOR='#00AA00'><B>INTO</B></FONT>", "<FONT COLOR='#00AA00'><B>VALUES</B></FONT>", "<FONT COLOR='#00AA00'><B>FROM</B></FONT>", "<FONT COLOR='#00CC00'><B>LEFT</B></FONT>", "<FONT COLOR='#00CC00'><B>JOIN</B></FONT>", "<FONT COLOR='#00AA00'><B>WHERE</B></FONT>", "<FONT COLOR='#AA0000'><B>LIMIT</B></FONT>", "<FONT COLOR='#00AA00'><B>ORDER BY</B></FONT>", "<FONT COLOR='#0000AA'><B>AND</B></FONT>", "<FONT COLOR='#0000AA'><B>OR</B> </FONT>", "<FONT COLOR='#0000AA'><B>DESC</B></FONT>", "<FONT COLOR='#0000AA'><B>ASC</B></FONT>", "<FONT COLOR='#00DD00'><B>ON</B> </FONT>" ), $query ); echo "<FONT COLOR='#0000FF'><B>SQL[".$SQL_INT."]:</B> ".$query."<FONT COLOR='#FF0000'>;</FONT></FONT><BR>\n"; $SQL_INT++; } //SQL_DEBUG ?> --was-- here's a neat little function I whipped up to do HTML color coding of SQL strings. /** * Output the HTML debugging string in color coded glory for a sql query * This is very nice for being able to see many SQL queries * @access public * @return void. prints HTML color coded string of the input $query. * @param string $query The SQL query to be executed. * @author Daevid Vincent [daevid@LockdownNetworks.com] * @version 1.0 * @date 04/05/05 * @todo highlight SQL functions. */ function SQL_DEBUG( $query ) { if( $query == '' ) return 0; global $SQL_INT; if( !isset($SQL_INT) ) $SQL_INT = 0; //[dv] this has to come first or you will have goofy results later. $query = preg_replace("/['\"]([^'\"]*)['\"]/i", "'<FONT COLOR='#FF6600'>$1</FONT>'", $query, -1); $query = str_ireplace( array ( '*', 'SELECT ', 'UPDATE ', 'DELETE ', 'INSERT ', 'INTO', 'VALUES', 'FROM', 'LEFT', 'JOIN', 'WHERE', 'LIMIT', 'ORDER BY', 'AND', 'OR ', //[dv] note the space. otherwise you match to 'COLOR' ;-) 'DESC', 'ASC', 'ON ' ), array ( "<FONT COLOR='#FF6600'><B>*</B></FONT>", "<FONT COLOR='#00AA00'><B>SELECT</B> </FONT>", "<FONT COLOR='#00AA00'><B>UPDATE</B> </FONT>", "<FONT COLOR='#00AA00'><B>DELETE</B> </FONT>", "<FONT COLOR='#00AA00'><B>INSERT</B> </FONT>", "<FONT COLOR='#00AA00'><B>INTO</B></FONT>", "<FONT COLOR='#00AA00'><B>VALUES</B></FONT>", "<FONT COLOR='#00AA00'><B>FROM</B></FONT>", "<FONT COLOR='#00CC00'><B>LEFT</B></FONT>", "<FONT COLOR='#00CC00'><B>JOIN</B></FONT>", "<FONT COLOR='#00AA00'><B>WHERE</B></FONT>", "<FONT COLOR='#AA0000'><B>LIMIT</B></FONT>", "<FONT COLOR='#00AA00'><B>ORDER BY</B></FONT>", "<FONT COLOR='#0000AA'><B>AND</B></FONT>", "<FONT COLOR='#0000AA'><B>OR</B> </FONT>", "<FONT COLOR='#0000AA'><B>DESC</B></FONT>", "<FONT COLOR='#0000AA'><B>ASC</B></FONT>", "<FONT COLOR='#00DD00'><B>ON</B> </FONT>" ), $query ); echo "<FONT COLOR='#0000FF'><B>SQL[".$SQL_INT."]:</B> ".$query."<FONT COLOR='#FF0000'>;</FONT></FONT><BR>\n"; $SQL_INT++; } //SQL_DEBUG http://php.net/manual/en/function.str-ireplace.php

« previous php.notes (#92367) next »