Jump to content

forum [quote] replacing


freelance84

Recommended Posts

If this were an example post in a forum:

$post = '[quote author=james]hello this is a quote[/quote]

here is some mor text between the next coming quote

[quote author=david]hello this is another quote[/quote]';

 

What is the best way to replace the

with opening html tag

eg:

<div class="quote"><div class="quoteTitle">author=x</div>

 

And then determine if the next is a [/quote ] is an opener or close quote?

 

And then of course there is the  issue of the user deleting a

or even placing a before an open quote...

 

Does anyone know of an example to look at?

Link to comment
https://forums.phpfreaks.com/topic/236272-forum-quote-replacing/
Share on other sites

I think preg_match should do the trick for you.

 

EX:

preg_match('/\[(quote) author=([a-zA-Z\'\s]+)]([a-zA-Z0-9\'\t\s\r\n\.]+)\[/quote\]/',$post,$match);

<div class="{$match[1]}"><div class="quoteTitle">author={$match[2]}</div>
<div class="{$match[1]}"><div class="quoteWords">{match[3]}</div>

 

You'll have to encapsulate $match[1] etc accordingly.

 

Note that the parenthesis in the regex mark subpatterns.

 

btw.  Let me know how many bugs are in my code  :)

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.