Jump to content

Code Parse Help


burhankhan

Recommended Posts

Hi:

 

I have written a class to parse bbcode.

 

I am having little problem with regular expression.

 

preg_replace('/\[quote\](.+?)\[\/quote\]/is', '<pre>$1</pre>', $mytext)

 

This is simple code to convert all QUOTES tags. It is working fine.

But when i have text like this:

 

[ quote ]here is some text[ quote ]here is more text[ / quote ][ / quote ]

 

Then it is creating problem.

It will print this:

 

[ quote ]here is some text

[ / quote ]

 

Is there any solution to parse 2 or more level QUOTES??

 

Thanks

Burhan Khan

Link to comment
https://forums.phpfreaks.com/topic/58963-code-parse-help/
Share on other sites

maybe call preg_replace more then one time

<?php
$mytext = '[quote]here is some text[quote]here is some text[/quote][/quote]';
while (preg_match('/\[quote\](.+?)\[\/quote\]/is', $mytext)) $mytext = preg_replace('/\[quote\](.+?)\[\/quote\]/is', '<pre>$1</pre>', $mytext);
echo $mytext;
?>

Link to comment
https://forums.phpfreaks.com/topic/58963-code-parse-help/#findComment-292612
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.