note 51618 added to function.str-ireplace

From: Date: Tue, 05 Apr 2005 20:14:54 +0000
Subject: note 51618 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-87531@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. /** * 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 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51618 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51618&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51618&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51618&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51618&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51618&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51618&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87531) next »