Page 9 of 13
Posted: Sat Jun 02, 2007 8:33 pm
by superdezign
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.
Posted: Sat Jun 02, 2007 8:40 pm
by ziggy3000
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
Code: Select all
$sql = preg_replace("#(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(<\/\\2>)(.*\*/)#", "<span class='comment'>\\1\\3\\5</span>", $sql);
Posted: Sat Jun 02, 2007 8:53 pm
by superdezign
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.
Posted: Sat Jun 02, 2007 9:35 pm
by ziggy3000
ok, using regex coach, i got the following regex
Code: Select all
(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(</[\w]*>)([^<>]\*/)
how would i use it?
$1, $3 and $5 are the things i need to highlight, right?
Posted: Sat Jun 02, 2007 9:39 pm
by superdezign
$1, $3, and $5 are the portions that you want to keep. Either preg_replace the rest out, or preg_match it and put it back together.
Posted: Sat Jun 02, 2007 9:40 pm
by ziggy3000
well, i am trying
Code: Select all
$sql = preg_replace("#(\/\*[^<>]*)(<([\w]+)[^>]*>)(.*)(<\/\\3*>)([^<>]\*/)#", "<span class='comment'>\\1\\3\\5</span>", $sql);
but's it doesn't work.
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];
}
Posted: Sat Jun 02, 2007 10:04 pm
by superdezign
Well, I can't really help you with "it won't work." You've gotta show me the result of the regex for me to know what's happening.\
(Heading to bed, so hopefully someone responds... If not, I'll help out in the morning.)
Posted: Sun Jun 03, 2007 1:25 pm
by ziggy3000
well, by it wont work, i meant that it wont remove the html tags so the result is the same as before.
Posted: Wed Jun 13, 2007 3:24 pm
by ziggy3000
SOMEONE PLEASE HELP ME!!!!!!!!!!!!!!!!
Posted: Wed Jun 13, 2007 4:11 pm
by superdezign
I
still need to see the regex and the result of it. We aren't magicians.

Posted: Wed Jun 13, 2007 4:16 pm
by ziggy3000
this is what i am trying
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 />";
}
and the result is that it highlights everything between /* and */, but if there is html tags between it, it wont highlight that.
Posted: Wed Jun 13, 2007 4:24 pm
by superdezign
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?

Posted: Wed Jun 13, 2007 4:31 pm
by ziggy3000
i can, but i want to learn what i am doing wrong.
Posted: Wed Jun 13, 2007 4:34 pm
by superdezign
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.
Code: Select all
(/\*.*)(<([\w]+)>)(.*)(</\3*>)(.*\*/)
You'll need to escape a few characters to bring it over to PHP.
Posted: Wed Jun 13, 2007 4:47 pm
by ziggy3000
ok, but i dont get how to implement the regex so that it leaves out the html tags.