MySQL highlighter
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Ooh. That wouldn't include the <br /> tag. Making progress. :-p
I'd never heard of back-referencing. At first glance, I thought it just copied the pattern to avoid too much typing, but it actually looks for the same content as the sub pattern. That's interesting.
And yeah, preg_match_all() definitely seems to be the function that you're after to get all of the HTML tags.
I'd never heard of back-referencing. At first glance, I thought it just copied the pattern to avoid too much typing, but it actually looks for the same content as the sub pattern. That's interesting.
And yeah, preg_match_all() definitely seems to be the function that you're after to get all of the HTML tags.
yea, but i can't get my pattern to work. i am adding one before and after the one on php.net which has the /* and */. can you use your regex coach(i dont know how to use it) and then tell me the pattern i need?
edit:
this is what i am using, but it doesn't work
edit:
this is what i am using, but it doesn't work
Code: Select all
$sql = preg_replace("#(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(<\/\\2>)(.*\*/)#", "<span class='comment'>\\1\\3\\5</span>", $sql);- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
I'm in the middle of converting my PHP4 classes to PHP5. PHP5 feels a lot more like C++. ^_^ Melikes.
Get Regex Coach, type the string you want to find a part of in the bottom box, and type in your regex piece by piece. You can see errors quickly.
If it's highlighted in yellow, its the whole pattern (return as the first element of the preg_match array), and you can highlight a sub pattern using the radio buttons below the string boxes. They'll correspond to the different sup patterns (1, 2, 3, etc.).
It's easy to just jump into because it makes sense. Start with simple regex and move into more complex regex.
Get Regex Coach, type the string you want to find a part of in the bottom box, and type in your regex piece by piece. You can see errors quickly.
If it's highlighted in yellow, its the whole pattern (return as the first element of the preg_match array), and you can highlight a sub pattern using the radio buttons below the string boxes. They'll correspond to the different sup patterns (1, 2, 3, etc.).
It's easy to just jump into because it makes sense. Start with simple regex and move into more complex regex.
ok, using regex coach, i got the following regex
how would i use it?
$1, $3 and $5 are the things i need to highlight, right?
Code: Select all
(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(</[\w]*>)([^<>]\*/)$1, $3 and $5 are the things i need to highlight, right?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
well, i am trying
but's it doesn't work.
ediT:
i am also trying this but it wont work
Code: Select all
$sql = preg_replace("#(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(<\/\\3*>)([^<>]\*/)#", "<span class='comment'>\\1\\3\\5</span>", $sql);ediT:
i am also trying this but it wont work
Code: Select all
preg_match_all("#(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(<\/\\3*>)([^<>]\*/)#", $sql, $match, PREG_SET_ORDER);
foreach($match as $var){
echo $var[1].$var[4].$var[6];
}- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
this is what i am trying
and the result is that it highlights everything between /* and */, but if there is html tags between it, it wont highlight that.
Code: Select all
preg_match_all("#(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(<\/\\3*>)([^<>]\*/)#", $sql, $match, PREG_SET_ORDER);
foreach($match as $var){
echo $var[1].$var[4].$var[6]."<br />";
}- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
I think you'll need to restart that regex, because you're right, it doesn't work.
Did you get Regex Coach yet? I'm playing around with this in it and I've already ran into a little speedbump... That when a comment is open, regardless of whether or not it closes, it will still comment everything after it. Are you sure you can't just use a pre-made parser?
Did you get Regex Coach yet? I'm playing around with this in it and I've already ran into a little speedbump... That when a comment is open, regardless of whether or not it closes, it will still comment everything after it. Are you sure you can't just use a pre-made parser?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Regex Coach will show you what you're doing wrong AS you're doing it. That's why I use it.
This works in Regex Coach when the comments are closed.
You'll need to escape a few characters to bring it over to PHP.
This works in Regex Coach when the comments are closed.
Code: Select all
(/\*.*)(<([\w]+)>)(.*)(</\3*>)(.*\*/)