Jump to content

regex help


ShaolinF

Recommended Posts

Hi Guys

 

I have written some regex which is meant to replace certain BBcode tags with the HTML equiv. It is not working as I intended. See problem and code below:

 

HTML I want to process:

[quote][quote=Jack][quote=John]hello mate, how you doing?[/quote]
Im fine thanks, you?[/quote]
Im good.[/quote]

 

PHP:

$searchArray = array(
'/(^\[quote=(.*)[\]]|\[quote\])/i', 
'/\[\/quote\]/i'
);
$replaceArray = array(
'<div class="quote">',
'</div>'
);

$message = preg_replace($searchArray, $replaceArray, $message);

 

It should give me this output:

<div class="quote">
   <div class="quote">
      <div class="quote">
          hello mate, how you doing?
      </div>
       Im fine thanks, you?
   </div>
     Im good.
</div>

 

But instead I get this:

<div class="quote">
[quote=Jack][quote=John]hello mate, how you doing?
</div>
Im fine thanks, you?
</div>
Im good.
</div>	

Link to comment
https://forums.phpfreaks.com/topic/200449-regex-help/
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.