freelance84 Posted May 12, 2011 Share Posted May 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236272-forum-quote-replacing/ Share on other sites More sharing options...
phpJoeMo Posted May 13, 2011 Share Posted May 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236272-forum-quote-replacing/#findComment-1214831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.