Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 696583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:04:42+00:00 2026-05-14T03:04:42+00:00

Okay, I’ve been working through a set of string replacments for bbcode style tags

  • 0

Okay, I’ve been working through a set of string replacments for bbcode style tags in my forum, replacing [b] and [i] etc is fairly simple as I can replace them directly without issue.

There are two tags that are giving me problems, as what I need to do with them is more complex. [quote] and [url] are fine, but, I would like to give users the choice of [quote=person_to_quote] and [url=URL]link text[/url], the [quote=] tag needs to be able to be nested too!

So I need to be able to replace the opening tag [quote= then retain the string add the ] show the quote and then end the [/quote]. I can replace the tags wholesale and retain the =person fine, but that is done by me cheating and simple adding the end tag to the text. What I’d really like to be able to do is pull everything between the = and ] store it so I can manipulate it separately.

Currently I’m using an array and simplye replacing the inline text thus:

    "[quote=" is replaced by "<span class=\"quote\">[Quote: ",

and just slapping the non-replaced text back on the end of it, that’s ugly though. What I’d like to be able to do is take the code saying [quote=person]some text here[/quote] and turn it into:

    "[quote=" is replaced by "<span class=\"quote\">$person says: ",

where $person would be a variable storing the person’s name so it can be replaced dynamically.

Similarly with the URLs I’d like to replace [url=link]link text[/url] and make it able to accept the url and replace it inline so the output is:

"[url=" is replaced by "<a href=$URL>"

with the html a tag already closed, which means stripping the url out, storing it then replacing it after.

So what method do I use to remove the text between = and the closing ] tags so what I pass into the replace array can be passed out and modified accordingly. Also I’m not worried about nesting in the quotes as the span class styling takes care of that, but I do need a function that can deal with any number of quote tags!.Thoughts please.

EDIT:

Just an update, I’ve solved the things I wanted to do, I modified the code webbiedave gave me and it works:

$output = preg_replace_callback(
'/\[quote=([^\]]+)?\]/',
create_function(
'$matches',
'return \'<span class="quote">\'.$matches[1].\' says: \';'
),
$comment);

then the close tag is picked up through my normal tag replace search afterwards anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:04:42+00:00Added an answer on May 14, 2026 at 3:04 am

    Try preg_replace_callback:

    $output = preg_replace_callback(
            '/\[quote=([^\]]+)?\]([^\[]+)?\[\/quote\]?/',
            create_function(
                '$matches',
                'return \'"[quote=" is replaced by "<span class=\"quote\">\'.$matches[1].\' says: ",\';'
            ),
            '[quote=person]some text here[/quote]'
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm working on a java server for an Apps backend, it must
Okay,I've been following this tutorial http://coenraets.org/blog/android-samples/androidtutorial/ Basically it gives me exactly what i need
Okay, I've set up a bit of code which searching for all the pages
Okay, so my paddle collision is working fine: if(velo.y > 0){ float t =
Okay, I hate facebook now. I've been fighting with this far too long. I'm
Okay so im working on this php image upload system but for some reason
Okay, my code is currently: public MySqlDataReader CreateQuery(string queryString, string connectionString ) { using
Okay, so I know that using eval() isn't great, but I haven't been able
Okay i know i have to use the JDBC etc, but im not sure
Okay, next PHPExcel question. I have an HTML form that users fill out and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.