Page 4 of 13

Posted: Wed May 30, 2007 6:30 pm
by ziggy3000
yes i have been trying and also looking here just in case, but in one of me previous post, nobody really helped me. they just looked at it, then nothing. i had to find out the solution myself. and there could also be some guest that were just surfing the forum, and liked the code, and decided to copy it.

Posted: Wed May 30, 2007 6:51 pm
by superdezign
:lol: I'm sure that any guest who read this thread would be more likely to get GeSHi than to steal your code. :-p

Posted: Wed May 30, 2007 6:52 pm
by RobertGonzalez
I would tend to agree with you SD.

Posted: Wed May 30, 2007 9:24 pm
by ziggy3000
so...

Posted: Wed May 30, 2007 9:32 pm
by superdezign
ziggy3000 wrote:so...
So... Is there still a problem in your code? Or should this thread be considered [Solved]?

Posted: Wed May 30, 2007 9:34 pm
by ziggy3000
yes! when it highlights = that's the only thing that gets highlighted! i want it to highlight all the stuff with out any html being highlighted

Posted: Wed May 30, 2007 9:37 pm
by superdezign
Whoa whoa whoa. You mean that, in all of this code:

Code: Select all

$sql = str_replace("\n", '<br />', $sql);
        $sql = preg_replace("/'(.+?)'/i", "<div style='color:red'> '\\1' </div>", $sql);
        $sql = preg_replace('/"(.+?)"/i', "<div style='color:red'> \"\\1\" </div>", $sql);
        $sql = preg_replace('/`(.+?)`/i', "<div style='color:red'> `\\1` </div>", $sql);
        $sql = str_replace('/=/', "<span style='color: green'>=</span>", $sql);
//      $sql = preg_replace("/(*)/", "<div style='color:brown'> \\1 </div>", $sql);
        $sql = preg_replace('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', "<div style='color:blue'>$1 $2 </div>", $sql);
        $sql = preg_replace('/.(SELECT|UPDATE)\s+/i', "<div style='color:blue'>\\1 </div>", $sql);
        $sql = preg_replace('/.(MAX|AVG|SUM|COUNT|MIN|FROM|INTO)\s+/i', "<div style='color:green'> \\1 </div>", $sql);
        $sql = preg_replace('/(ASC|DESC|ORDER BY|LIMIT|LEFT|JOIN|WHERE|MODIFY|CHANGE|DISTINCT)/i', "<div style='color:green'> \\1 </div>", $sql);
        $sql = preg_replace('/(LIKE|NOT LIKE|REGEXP)/i', "<div style='color:orange'> \\1 </div>", $sql);
        $sql = preg_replace('/(INT|VARCHAR|TINYINT|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|CHAR|CHARACTER'.
'|DATE|DATETIME|DEC|DECIMAL|DOUBLE|ENUM|FLOAT|FLOAT4|FLOAT8|INT1|INT2|INT3|INT4|INT8|INTEGER|'.
'LONGBLOB|LONGTEXT|MEDIUMBLOB|MEDIUMTEXT|MEDIUMINT|MIDDLEINT|NCHAR|NUMERIC|REAL|SERIAL|SET|'.
'SMALLINT|TEXT|TIME|TIMESTAMP|TINYBLOB|TINYTEXT|VARBINARY|YEAR|PRIMARY|AUTO INCREMENT)/i', "<div style='color:darkred'> \\1 </div>", $sql);
        $sql = preg_replace('/;/i', "<b><div style='color: green;'> ;</div></b>", $sql);
        $sql = preg_replace('/[0-9]{6}/i', "<div style='color: red;'> \\1 </div>", $sql);
The only thing that works is:

Code: Select all

$sql = str_replace('/=/', "<span style='color: green'>=</span>", $sql);
:?:

Posted: Wed May 30, 2007 9:42 pm
by superdezign
I tested your code. The equals sign is the only thing that doesn't work.

You have two errors in your regex though.

This:

Code: Select all

$sql = preg_replace('/.(SELECT|UPDATE)\s+/i', "<div style='color:blue'>\\1 </div>", $sql);
        $sql = preg_replace('/.(MAX|AVG|SUM|COUNT|MIN|FROM|INTO)\s+/i', "<div style='color:green'> \\1 </div>", $sql);
Should be this:

Code: Select all

$sql = preg_replace('/(SELECT|UPDATE)\s+/i', "<div style='color:blue'>\\1 </div>", $sql);
        $sql = preg_replace('/(MAX|AVG|SUM|COUNT|MIN|FROM|INTO)\s+/i', "<div style='color:green'> \\1 </div>", $sql);
(Remove the periods at the start of the regex)

And please, use inline elements. Span works fine. And on the spot <b> and <div style="">, you could condense it to simply <b style="">.

Posted: Wed May 30, 2007 9:50 pm
by ziggy3000
k, i did what you said. here's my code now

Code: Select all

$sql = str_replace("\n", '<br />', $sql);
	$sql = preg_replace("/'(.+?)'/i", "<div style='color:red'> '\\1' </div>", $sql);
	$sql = preg_replace('/"(.+?)"/i', "<div style='color:red'> \"\\1\" </div>", $sql);
	$sql = preg_replace('/`(.+?)`/i', "<div style='color:red'> `\\1` </div>", $sql);
 	$sql = str_replace('/=/', "<span style='color: green'>=</span>", $sql);
//	$sql = preg_replace("/(*)/", "<div style='color:brown'> \\1 </div>", $sql);
	$sql = preg_replace('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', "<div style='color:blue'>$1 $2 </div>", $sql);
	$sql = preg_replace('/(SELECT|UPDATE)\s+/i', "<div style='color:blue'>\\1 </div>", $sql);
	$sql = preg_replace('/(MAX|AVG|SUM|COUNT|MIN|FROM|INTO)\s+/i', "<div style='color:green'> \\1 </div>", $sql);
	$sql = preg_replace('/(ASC|DESC|ORDER BY|LIMIT|LEFT|JOIN|WHERE|MODIFY|CHANGE|DISTINCT)/i', "<div style='color:green'> \\1 </div>", $sql);
	$sql = preg_replace('/(LIKE|NOT LIKE|REGEXP)/i', "<div style='color:orange'> \\1 </div>", $sql);
	$sql = preg_replace('/(INT|VARCHAR|TINYINT|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|CHAR|CHARACTER'.
'|DATE|DATETIME|DEC|DECIMAL|DOUBLE|ENUM|FLOAT|FLOAT4|FLOAT8|INT1|INT2|INT3|INT4|INT8|INTEGER|'.
'LONGBLOB|LONGTEXT|MEDIUMBLOB|MEDIUMTEXT|MEDIUMINT|MIDDLEINT|NCHAR|NUMERIC|REAL|SERIAL|SET|'.
'SMALLINT|TEXT|TIME|TIMESTAMP|TINYBLOB|TINYTEXT|VARBINARY|YEAR|PRIMARY|AUTO INCREMENT)/i', "<div style='color:darkred'> \\1 </div>", $sql); 
	$sql = preg_replace('/;/i', "<b style='color: green;'> ;</b>", $sql);
	$sql = preg_replace('/[0-9]{6}/i', "<div style='color: red;'> \\1 </div>", $sql);
so how should i get the equal sign to work?

Posted: Wed May 30, 2007 9:54 pm
by superdezign
Take the delimiters out of str_replace. str_replace does not run on regex.

And you're still not using inline elements! Span, man, span! :D

Posted: Wed May 30, 2007 9:55 pm
by ziggy3000
now it semi-echoing html code also...

Posted: Wed May 30, 2007 9:57 pm
by superdezign
Completely clueless as to what you mean.

Posted: Wed May 30, 2007 9:59 pm
by ziggy3000
now it echoing
='color:red'>
instead of the equal sign and the preg_replace above that code doesn't work

Posted: Wed May 30, 2007 10:00 pm
by John Cartwright
I see you ignored d11's advise.

Posted: Wed May 30, 2007 10:03 pm
by ziggy3000
i'm getting confused by reading his advise. i don't know what tokenize means and...
can someone translate that into basic english?