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

  • SEARCH
  • Home
  • 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 8852415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:23:42+00:00 2026-06-14T13:23:42+00:00

I want to count the curly brackets in a PHP source code, so i

  • 0

I want to count the curly brackets in a PHP source code, so i can eventually find the end of a method/function in the given source code.

I was adviced to use the token_get_all() function for this job. But for some reason it isn’t splitting the given source into tokens.

I’m using the following code to test it:

<?php
$str = 'class someClass{
    public $var1;
    private $var2 = null;

    public function func1 ( $someVar )
    {
        echo $someVar;
    }

    public function func2 ( )
    {
        return false;
    }
}';

$bla = token_get_all ( $str );

echo '<pre>';
print_r ( $bla );
echo '</pre>';
?>

But this results in:

Array
(
    [0] => 311
    [1] => class someClass{
    public $var1;
    private $var2 = null;

    public function func1 ( $someVar )
    {
        echo $someVar;
    }

    public function func2 ( )
    {
        return false;
    }
}
    [2] => 1
)

So right now i’m kinda stuck with this. Why doesn’t the token_get_all() tokenize the given source code..?

  • 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-14T13:23:44+00:00Added an answer on June 14, 2026 at 1:23 pm

    Because the parser starts in HTML context (just like PHP itself), so the entire string you have passed to token_get_all is actually a single HTML token. You need to add <?php at the start of your $str.

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

Sidebar

Related Questions

I want to count how many members of an iterable meet a given condition.
I want to count totals for all mondays, tuesdays, etc. for any given (user
I want to count how many / s I could find in a string.
I want to count number of files in a folder in a remote host.
I want to count the numbers of hard tab characters in my documents in
We want to count number of shakes done by user. We tried motionBegan, motionEnded
I want to count the rows in several date ranges (i.e: last hour, today,
I want to count how many times i built on VS.NET . I have
I want to count the number of accounts from the resulting table generated from
I want to count the total divs inside a container and toggle their visibilities

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.