I am trying to remove a nested quote from my message board, but I am having some problems.
Input Example:
[quote author = personX link = topic = 12.msg1910 # msg1910 date = 1282745641]
[quote author=PersonY link=topic=12.msg1795#msg1795 date=1282727068]
The message in the original quote
[/quote]
Second message quoting the first
[/quote]
[quote author = PersonZ link = topic = 1.msg1 # msg1 date = 1282533805]
Random Third Quote
[/quote]
Output example
[quote author = personX link = topic = 12.msg1910 # msg1910 date = 1282745641]
Post in the second quote
[/quote]
[quote author = PersonZ link = topic = 1.msg1 # msg1 date = 1282533805]
Random Third Quote
[/quote]
As you can see, the attached quote (the original message) is deleted along with the quote tags.
I canβt figure it out.
When i try
$toRemove = '(\\[)(quote)(.*?)(\\])';
$string = $txt;
$found = 0; echo preg_replace("/($toRemove)/e", '$found++ ? \'\' : \'$1\'', $string);
It removes every occurrence of the quote tag except the first,
But when I deploy the code to:
$toRemove = '(\\[)(quote)(.*?)(\\])(.*?)(\\[\\/quote\\])';
$string = $txt;
$found = 0; echo preg_replace("/($toRemove)/e", '$found++ ? \'\' : \'$1\'', $string);
He does nothing at all.
Any ideas on this?
Edit:
Thank you for your help, Haji.
I'm still having a problem.
While loop around
while ( $input = preg_replace_callback( '~\[quoute.*?\[/quote\]~i', 'replace_callback', $input ) ) {
}
, ( u quoute) .
,
$input = preg_replace_callback( '/\[quote(.*?)/i', 'replace_callback', $input );
,
$input = preg_replace_callback( '/\[quote(.*?)\[\/quote\]/i', 'replace_callback', $input );
.
, undo_replace, , . , sha1, , .
, :
$cache = array();
$input = $txt;
function replace_callback( $matches ) {
global $cache;
$hash = sha1( $matches[0] );
$cache["hash"] = $matches[0];
return "REPLACE:$hash";
}
$input = preg_replace_callback( '/\[quote(.*?)\[quote\]/i', 'replace_callback', $input );
function undo_replace( $matches ) {
global $cache;
return $cache[$matches[1]];
}
$input = preg_replace_callback( '~REPLACE:[a-f0-9]{40}~i', 'undo_replace', $input );
$input = preg_replace( '~REPLACE:[a-f0-9]{40}~i', '', $input );
echo $input;
:)