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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:00:34+00:00 2026-05-22T00:00:34+00:00

I have wrote a Quote function for my own personal forum, in a website

  • 0

I have wrote a Quote function for my own personal forum, in a website written with PHP.

The message quoted tags looks like [quote=username]message[/quote], so I wrote that function :

$str=preg_replace('#\[quote=(.*?)\](.*?)\[/quote\]#is', '<div class="messageQuoted"><i><a href="index.php?explore=userview&userv=$1">$1</a> wrote :</i>$2</div>', $str);

This one works if the quote is one, but then a user quote a quote, this doesnt works. So I need a sort of recursive quote for apply this behaviour.

I tried to searching on SO many topics, but I don’t really understand how it can works.
Would be appreciated any suggestions/tips for do this kind of operation! Let me know, and thanks!

EDIT

At the end, this is my own solution :

if(preg_match_all('#\[quote=(.*?)\](.*?)#is', $str, $matches)==preg_match_all('#\[/quote\]#is', $str, $matches)) {
    array_push($format_search, '#\[quote=(.*?)\](.*?)#is');
    array_push($format_search, '#\[/quote\]#is');

    array_push($format_replace, '<div class="messageQuoted"><a class="lblackb" href="index.php?explore=userview&userv=$1">$1</a> wrote :<br />$2');
    array_push($format_replace, '</div>');
}

$str=preg_replace($format_search, $format_replace, $str);

it repleace only if the number of occurences is correct. So it should (right?) to prevent html broke or other malicious attack. What do you think?

  • 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-22T00:00:35+00:00Added an answer on May 22, 2026 at 12:00 am

    You can simply replace the opening quote tag with the opening div tag and same for the closing section. This only goes bad if the user messes up it’s quote tag matching.
    Alternatively you can recurse the quote function with the inner section:

    <?php
    function quote($str)
    {
        if( preg_match('#\[quote=.*?\](.*)\[/quote\]#i', $str) )
             return quote(preg_replace('#\[quote=.*?\](.*)\[/quote\]#i', '$1', $str);
        return preg_replace('#\[quote=.*?\](.*)\[/quote\]#', '<div blabla>$1</div>', $str);
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can PHP dissect its own syntax? For example, I'd like to write a function
So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
I'm attempting to write a Python function to send an email to a list
By default Html.ValidationSummary() produces HTML like this: <span class=validation-summary-errors>There were some errors...</span> <ul class=validation-summary-errors>
I have a Django app that gets it's data completely from an external source
While writing a game for J2ME we ran into an issue using java.lang.Integer.parseInt() We
I'm not a beginner, but the more I think about this issue, the more
I've read and looked a quite a few examples for Threadpooling but I just
template< class T1, class T2 > class Pair { T1 first; T2 second; };
It started quite normally. I'm writing complex calculation application for iPhone. I decided to

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.