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
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Fri May 25, 2007 5:12 pm
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.
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Fri May 25, 2007 6:06 pm
would it be
'\\1\\2 '
if it isn't, can u just tell me what it is?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri May 25, 2007 6:09 pm
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 » Fri May 25, 2007 6:10 pm
it doesnn't work
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Fri May 25, 2007 6:20 pm
i'm trying to parse CREATE DATABASE, but it doesn't highlight...
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri May 25, 2007 6:38 pm
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 » Fri May 25, 2007 6:40 pm
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
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri May 25, 2007 6:41 pm
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 » Fri May 25, 2007 6:44 pm
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 » Fri May 25, 2007 6:45 pm
nevermind, it works
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri May 25, 2007 6:51 pm
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.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri May 25, 2007 6:53 pm
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri May 25, 2007 6:57 pm
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?