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
tony montana
Forum Newbie
Posts: 21 Joined: Tue Sep 28, 2004 11:10 am
Post
by tony montana » Tue Sep 28, 2004 11:12 am
Ok so both my quote tags work, I used str replace before but users could use [ end quote] (end == /) and break the tables.
So Im using preg replace, however when a quote tag of the same kind is within another it works, but if a is in b then it doesn work (vica versa).
a = [ quote ]
b = [ quote = var ]
Regex
Code: Select all
$forumz_post = preg_replace('/(?<!\\\\)\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si',
"<table cellspacing="1" cellpadding="4" class="table">
<tr><td class="headbars">Quote</td></tr>
<tr><td class="cell">\\1</td></tr></table>\n", $forumz_post);
$forumz_post = preg_replace('/(?<!\\\\)\[quote(?::\w+)?=(?:"|"|'')?(.*?)["'']?(?:"|"|'')?\](.*?)\[\/quote\]/si',
"<table cellspacing="1" cellpadding="4" class="table">
<tr><td class="headbars">Quote (\\1)</td></tr>
<tr><td class="cell">\\2</td></tr></table>\n", $forumz_post);
You can see tests (specifically the top one - which shows the problem) here ;
http://forumz.wuggawoo.co.uk/index/test
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 12:59 pm
try switching the order you are running them. ([quote=] first)
tony montana
Forum Newbie
Posts: 21 Joined: Tue Sep 28, 2004 11:10 am
Post
by tony montana » Tue Sep 28, 2004 1:16 pm
Nah didnt work.
I need to somehow impliment it to read
[ quote ] or [ quote = var ]
Actually, no, this wont work :S
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 1:20 pm
I've used [php_man]preg_match_all[/php_man] to calculate the nesting orders..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 1:39 pm
how about this
Code: Select all
preg_match_all('#(\[quote(=(["'']?)(.*?)\\3)?\]|\[/quote\])#is',$text,$matches,PREG_OFFSET_CAPTURE)
Last edited by
feyd on Sat Feb 11, 2006 4:54 pm, edited 1 time in total.
tony montana
Forum Newbie
Posts: 21 Joined: Tue Sep 28, 2004 11:10 am
Post
by tony montana » Tue Sep 28, 2004 3:02 pm
Ok still 0, but why am I doing that anyway?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 3:05 pm
so you can correctly determine the nesting order to do your regular expression run.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 3:35 pm
preg_match* only checks for matches.. I wouldn't expect it to actually do any major processing
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 3:47 pm
when I've used preg_match* to handle nesting, I used the matches to determine which order to do the preg_replaces in.. deepest sets first, in order of appearance.
tony montana
Forum Newbie
Posts: 21 Joined: Tue Sep 28, 2004 11:10 am
Post
by tony montana » Tue Sep 28, 2004 3:48 pm
Well thats the thing, I cant determine an order because with two types of quote tags theres so many combinations.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Sep 28, 2004 4:01 pm
I certainly did when I wrote a handler for nesting.. you could also use the outer going in with str_replace.
tony montana
Forum Newbie
Posts: 21 Joined: Tue Sep 28, 2004 11:10 am
Post
by tony montana » Tue Sep 28, 2004 4:07 pm
Nah, thats why Im doing all this, users could just do [ /quote ] and screw up the table.