Page 1 of 1

Removing the first quotes

Posted: Sat Jan 29, 2005 6:51 am
by azz0r_
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 = "&#1111;quote=by azz0r at 28th Jan 8:15pm] &#1111;quote=by Jack at 28th Jan 3:50pm] &#1111;quote=by azz0r at 28th Jan 12:18pm] :lol: :lol: &#1111;/quote]

Wow, that's <span style='color:blue' title='I&#39;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. &#1111;/quote]

:lol: :lol:

:gtfo: &#1111;/quote]";

	preg_match_all('/(?<!\\\\)\&#1111;quote(?::\w+)?\]/i', $forumz_post, $quote_open);
	preg_match_all('/(?<!\\\\)\&#1111;quote(?::\w+)?=(?:"|"|'')?(.*?)&#1111;"'']?(?:"|"|'')?\]/i', $forumz_post, $quote_opens);
	preg_match_all('/(?<!\\\\)\&#1111;\/quote(?::\w+)?\]/i', $forumz_post, $qe);

	$qopen = count($quote_open&#1111;0]) + count($quote_opens&#1111;0]);
	$qend = count($qe&#1111;0]);

	if($qopen == $qend)
	&#123;$forumz_post = str_replace('&#1111;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('/(?<!\\\\)\&#1111;quote(?::\w+)?=(?:"|"|'')?(.*?)&#1111;"'']?(?:"|"|'')?\]/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('&#1111;/quote]', '</td></tr></table>', $forumz_post);&#125;
	
	echo $forumz_post;

Posted: Sat Jan 29, 2005 7:40 am
by azz0r_
JimmyJohansen wrote:ok...
:x are you gonna help or just spam

Posted: Sat Jan 29, 2005 7:44 am
by azz0r_
Waste of time and space.

Bye

Posted: Sat Jan 29, 2005 8:04 am
by azz0r_
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('`\&#1111;quote\](.+?)\&#1111;/quote\]`is', '', $forumz_post); 
	$forumz_post = preg_replace('`\&#1111;quote=(&#1111;^\\&#1111;]*)\](.+?)\&#1111;/quote\]`is', '', $forumz_post);
	$forumz_post = eregi_replace("\\&#1111;quote=(&#1111;^\\&#1111;]*)\\](&#1111;^\\&#1111;]*)\\&#1111;/quote\\]","", $forumz_post);

Posted: Sat Jan 29, 2005 1:58 pm
by azz0r_
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.

Posted: Sat Jan 29, 2005 2:41 pm
by timvw
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.

Posted: Sat Jan 29, 2005 3:02 pm
by azz0r_
grr Id have thought some quote tag removal code wouldve already been around.

I know vB for example can do it.