MySQL highlighter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

MySQL highlighter

Post by ziggy3000 »

i am creating a mysql highlighter
and i need help.

what should i put in the replacement part between the 2 div tags?

Code: Select all

<?php
$sql = preg_replace('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', "<div style='color:blue'></div>", $sql);
?>
Last edited by ziggy3000 on Thu May 31, 2007 6:24 pm, edited 2 times in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Have you looked at http://www.php.net/function.preg_replace to see how to reference your matches?
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

would it be

'\\1\\2 '

if it isn't, can u just tell me what it is?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try it, it is all clearly documented under the replacement parameter header
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

it doesnn't work :(
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

i'm trying to parse CREATE DATABASE, but it doesn't highlight...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

CREATE DATABASE
your reguar expression requires one or more spaces after DATABASE
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

in the code i am parsing it is, i just didn't show it up here

the actual code i am parsing is
CREATE DATABASE hi
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$sql = preg_match(..., "<div style='color:blue'>$1 $2</div>", ...);
works for me
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

it's echoing 0.
can you display the full code you're using, and what you're entering
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

nevermind, it works
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

your welcome :wink:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I thought GeSHi parsed SQL as a language, in addition to PHP. That might be a good place to learn how to make highlighters and parsers.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Everah wrote:I thought GeSHi parsed SQL as a language, in addition to PHP.

Code: Select all

SELECT `answer` FROM `jcart` LIMIT 1
You thought right
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I thought so. Of course, I am also the guy that thought it would be easier to download a complete application instead of rebuilding it from scratch without a thorough understanding of regular expressions, too. So what do I know? ;)
Post Reply