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 8631443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:11+00:00 2026-06-12T09:13:11+00:00

Possible Duplicate: php regex [b] to <b> I’m having trouble with regex, I’m an

  • 0

Possible Duplicate:
php regex [b] to <b>

I’m having trouble with regex, I’m an absolute regex noob. I can’t see what’s going wrong with trying to convert the HTML back to the ‘BBCode’.

Could somebody take a look at the ‘unquote’ function and tell me the obvious mistake I’m making? (I know it’s obvious because I always find the un-obvious errors)

NOTE: I’m not using recursive Regex because I couldn’t get my head around it and already started this way round of sorting out the Quotes so they’re nested.

<?php
function quote($str){
    $str = preg_replace('@\[(?i)quote=(.*?)\](.*?)@si', '<div class="quote"><div class="quote-title">\\1 wrote:</div><div class="quote-inner">\\2', $str);
    $str = preg_replace('@\[/(?i)quote\]@si', '</div></div>', $str);
    return $str;
}

function unquote($str){
    $str = preg_replace('@\<(?i)div class="quote"\>\<(?i)div class="quote_title"\>(.*?)wrote:\</(?i)div\><(?i)div class="quote-inner"\>(.*?)@si', '[quote=\\1]\\2',  $str);
    $str = preg_replace('@\</(?i)div\></(?i)div\>@si', '[/quote]', $str);
}
?>

This is just some code to help test it:

<html>
<head>
    <style>
    body {
        font-family: sans-serif;
    }
    .quote {
        background: rgba(51,153,204,0.4)  url(../img/diag_1px.png);
        border: 1px solid rgba(116,116,116,0.36);
        padding: 5px;
    }

    .quote-title, .quote_title {
        font-size: 18px;
        margin: 5px;
    }

    .quote-inner {
        margin: 10px;
    }
    </style>
</head>
<body>
    <?php
    $quote_text = '[quote=VCMG][quote=2xAA]DO RECURSIVE QUOTES WORK?[/quote]I have no idea.[/quote]';
    $quoted = quote($quote_text);
    echo $quoted.'<br><br>'.unquote($quoted); ?>
</body>

Thanks in advance, Sam.

  • 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-06-12T09:13:12+00:00Added an answer on June 12, 2026 at 9:13 am

    Well, you could start by setting you php class to either quote-title or quote_title but keep it consistent.

    Then, add a return $str; to your second function and you should be nearly there.

    And you can simplify your regex’s a little :

    function quote($str){
        $str = preg_replace('@\[quote=(.*)\]@siU', '<div class="quote"><div class="quote-title">\\1 wrote:</div><div class="quote-inner">', $str);
        $str = preg_replace('@\[/quote\]@si', '</div></div>', $str);
        return $str;
    }
    
    function unquote($str){
        $str = preg_replace('@<div class="quote"><div class="quote-title">(.*) wrote:</div><div class="quote-inner">@siU', '[quote=\\1]',  $str);
        $str = preg_replace('@</div></div>@si', '[/quote]', $str);
        return $str;
    }
    

    But beware of replacing with different calls the start and end tags of your quotes. I thin that unquote can create some strange behaviours if you happen to have other bbcode creating </div></div> code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: simple regex in php, formatting decimal number How to convert a digit
Possible Duplicate: PHP REGEX: Get domain from URL I am working on a project
Possible Duplicate: php regex , extract phone number from text/html I have following requirement.
Possible Duplicate: PHP remove special character from string I want to find a regex
Possible Duplicate: PHP method chaining? I occasionally see some php applications use classes like
Possible Duplicate: php regex <b> to <b> Inside my admin panel I have a
Possible Duplicate: PHP convert XML to JSON Here is what my a sample of
Possible Duplicate: PHP date time Trying to add one second to a datetime that
Possible Duplicate: PHP 2-way encryption: I need to store passwords that can be retrieved
Possible Duplicate: php regex to get string inside href tag I have a text

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.