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
azz0r_
Forum Commoner
Posts: 27 Joined: Mon Jan 24, 2005 4:15 pm
Post
by azz0r_ » Sat Jan 29, 2005 6:51 am
You know how its done on many forums where say you have a quote tree of about 4 people and when someone trys to add another one it gets stripped to one.
How would I do?
I have the code to display the quotes (below) but Im thinking somehow using preg_match_all and then some form of regex to remove the first ones leaving the last.
Code: Select all
<?PHP
$forumz_post = "їquote=by azz0r at 28th Jan 8:15pm] їquote=by Jack at 28th Jan 3:50pm] їquote=by azz0r at 28th Jan 12:18pm] :lol: :lol: ї/quote]
Wow, that's <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> hilarious.
Remind me to :lol: next time you fall off a 6-foot high structure onto your face and can't breathe. ї/quote]
:lol: :lol:
:gtfo: ї/quote]";
preg_match_all('/(?<!\\\\)\їquote(?::\w+)?\]/i', $forumz_post, $quote_open);
preg_match_all('/(?<!\\\\)\їquote(?::\w+)?=(?:"|"|'')?(.*?)ї"'']?(?:"|"|'')?\]/i', $forumz_post, $quote_opens);
preg_match_all('/(?<!\\\\)\ї\/quote(?::\w+)?\]/i', $forumz_post, $qe);
$qopen = count($quote_openї0]) + count($quote_opensї0]);
$qend = count($qeї0]);
if($qopen == $qend)
{$forumz_post = str_replace('їquote]', "<table cellspacing="1" cellpadding="4" class="table">
<tr><td class="headbars">Quote</td></tr>
<tr><td class="cell">", $forumz_post);
$forumz_post = preg_replace('/(?<!\\\\)\їquote(?::\w+)?=(?:"|"|'')?(.*?)ї"'']?(?:"|"|'')?\]/i',
"<table cellspacing="1" cellpadding="4" class="table">
<tr><td class="headbars">Quote (\\1)</td></tr>
<tr><td class="cell">", $forumz_post);
$forumz_post = str_replace('ї/quote]', '</td></tr></table>', $forumz_post);}
echo $forumz_post;
azz0r_
Forum Commoner
Posts: 27 Joined: Mon Jan 24, 2005 4:15 pm
Post
by azz0r_ » Sat Jan 29, 2005 7:40 am
JimmyJohansen wrote: ok...
are you gonna help or just spam
azz0r_
Forum Commoner
Posts: 27 Joined: Mon Jan 24, 2005 4:15 pm
Post
by azz0r_ » Sat Jan 29, 2005 7:44 am
Waste of time and space.
Bye
azz0r_
Forum Commoner
Posts: 27 Joined: Mon Jan 24, 2005 4:15 pm
Post
by azz0r_ » Sat Jan 29, 2005 8:04 am
Anyway its worth noting that the code in my first post is used because its virtually impossible to regex the quote tag and its nesting order properly.
Thus thats why Im asking for help on actually making a regex to replace the quotes with nothing.
So far Ive got these going - not working how Id hoped.
Code: Select all
$forumz_post = preg_replace('`\їquote\](.+?)\ї/quote\]`is', '', $forumz_post);
$forumz_post = preg_replace('`\їquote=(ї^\\ї]*)\](.+?)\ї/quote\]`is', '', $forumz_post);
$forumz_post = eregi_replace("\\їquote=(ї^\\ї]*)\\](ї^\\ї]*)\\ї/quote\\]","", $forumz_post);
azz0r_
Forum Commoner
Posts: 27 Joined: Mon Jan 24, 2005 4:15 pm
Post
by azz0r_ » Sat Jan 29, 2005 1:58 pm
Bump.
This is why I used the preg_match_all before - its too hard to write a regex that recognizes dynamic quote tags and normal quote tags.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sat Jan 29, 2005 2:41 pm
for text parsing, especially nested tags, usage of regular expressions usually results in a lot of problems...
you're much better of with a stack where you can keep track in what segment/tag you are. excellent exercise for an implementation of the state pattern too.
meaby
http://cgi.mcgruff.plus.com/php/search_engine/ can inspire you.
azz0r_
Forum Commoner
Posts: 27 Joined: Mon Jan 24, 2005 4:15 pm
Post
by azz0r_ » Sat Jan 29, 2005 3:02 pm
grr Id have thought some quote tag removal code wouldve already been around.
I know vB for example can do it.