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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:07:37+00:00 2026-06-02T22:07:37+00:00

So in my PHP code I have a string like so; The quick brown

  • 0

So in my PHP code I have a string like so;

The quick brown {{fox($a);}} jumped over the lazy {{dog($b);}}.

Now it might sound weird, but I want to go through the string, and collect all the BBCode style tags.

Then I want to eval() all the functions which are inside the {{}}‘s. So I’d eval fox($a); and dog($b);.

Both of these functions return a string. And I want to replace the respective tags with the respective results. So supposing fox() returns “vulpes vulpes” and dog() returns “canis lupus”, my original string would look like this;

The quick brown vulpes vulpes jumped over the lazy canis lupus.

However, I am famously terrible with regular expressions, and I have no idea how to go about this.

Any advice would be welcome!

(And yes, I am aware of the dangers of happy-go-lucky eval()ing. However, these strings come strictly from the developers and no user will ever be able to eval anything.)

  • 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-02T22:07:39+00:00Added an answer on June 2, 2026 at 10:07 pm

    If you want to do this with a regex, here’s a solution that seemed to work for me:

    function fox( $a) { return $a . 'fox!'; }
    function dog( $b) { return $b . 'dog!'; }
    
    $a = 'A'; $b = 'B';
    $string = 'The quick brown {{fox($a);}} jumped over the lazy {{dog($b);}}.';
    $regex  = '/{{([^}]+)+}}/e';
    $result = preg_replace( $regex, '$1', $string);
    

    The regex is pretty simple:

    {{       // Match the opening two curly braces
    ([^}]+)+ // Match any character that is not a closing brace more than one time in a capturing group
    }}       // Match the closing two curly braces
    

    Of course, the /e modifier causes the replacement to be eval‘d, producing this:

    Output:

    var_dump( $result);
    // string(49) "The quick brown Afox! jumped over the lazy Bdog!."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have i string in my PHP-code which looks like this Bokad av Anna
In my PHP code I have a date in my variable $postedDate. Now I
So I have some PHP code that looks like: $message = 'Here is the
I have a string like this The theme song of whatever - http://www.anydomain.com/pop_new.php?sid=10623&aid=1581&rand=0.6808111508818073 #string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a JSON String like this $test='{var1:null,var3:null,status:{code:150,message:blah blah}}'; I want to access the
I have a longitude and latitude as a string in PHP like below 49.648881
Say i have this PHP code: $FooBar = a string; i then need a
i have a string like this : string_data = <option value='1'>ahmad</option><option value='2'>mohammad</option><option value='3'>ali</option> now
In some PHP code, I have an mysql_real_escape_string()'d term, like foo\'s . I search

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.