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
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  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.