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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:38+00:00 2026-05-26T05:45:38+00:00

exapmle function hello(){ echo ‘hello’; foreach (array(1,2,3) as $n) { echo $n; } echo

  • 0

exapmle

function hello(){
    echo 'hello';
    foreach (array(1,2,3) as $n)
    {
        echo $n;
    }
    echo 'bye-bye';
    echo 'bye-bye';
    echo 'bye-bye';
}
function hi(){}

I need everything that is between outer curly brackets, ignoring any inner curly brackets, so my result wont be like that

{
    echo 'hello';
    foreach (array(1,2,3) as $n)
    {
        echo $n;
    }

or

{
    echo 'hello';
    foreach (array(1,2,3) as $n)
    {
        echo $n;
    }
    echo 'bye-bye';
    echo 'bye-bye';
    echo 'bye-bye';
}
function hi(){}
  • 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-26T05:45:39+00:00Added an answer on May 26, 2026 at 5:45 am

    In the general case this is not doable with regular expressions. You will need to use a parser designed for the task, or write one of your own.

    For basic functionality you don’t need much: read characters one at a time, keep a count of how many unclosed braces you have at any one point and consider parsing complete when this number decreases from 1 to 0.

    The next step would be to recognize common string literals (single and double quoted) and correctly skip any literal braces in those strings, which would be enough to get you 90% of the way.

    Update: here’s an asnwer to a similar problem that also includes sample code (although it’s in C# instead of PHP).

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

Sidebar

Related Questions

I need a function that I can call when somthing is done, for example
$.get(http://localhost/code.php, function(data){ alert(data); }); code.php: <?php echo hello!; ?> I also tried other variants
This example is from php.net: <?php function Test() { static $a = 0; echo
foreach($arrayOne as $value){ do function } In the above example, I'd like to pass
I've seen a lot of example c++ code that wraps function calls in a
I'm wondering if there are any syntactic problems calling a function that only has
I just realized that you can't just use an if statement on a function,
For example, in foo.php: <?php echo 'hello'; ?> And in bar.php, I want to
For example I have the following code: function a($param) { function b() { echo
I have a simple question related to one-line programming. First an example: function test(a)

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.