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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:22:41+00:00 2026-05-28T15:22:41+00:00

Sorry if this question has already been answered elsewhere. I looked through stack overflow

  • 0

Sorry if this question has already been answered elsewhere. I looked through stack overflow and couldn’t find exactly what I was looking for.

I need to know how to scan multiple php files in a single directory (test/ for example), and extract text between specific “tagged” areas on each php file.

Example of “tagged” areas:

<?
/*
{('test1')}
*/
?>

<div>text here</div>

<?
/*
{('test2')}
*/
?>

And the code would display test1, test2, etc. and ignore anything else. I tried looking into fopen(), file_get_contents and preg_match_all but each time they only find the first occurrence and not every occurrence of the “tagged” areas. Any help would be great!

EDIT – WHAT I CURRENTLY HAVE:

foreach (glob("templates/*.php") as $fn) {

$file = file_get_contents($fn);

preg_match_all("#\{\('(\w+)'\)}#", $file, $matches);   

$variable = join('', $matches[1]);

echo $variable.'<br />';

How do I add array_chunk to this so that each iteration of test is echo’d as it’s own variable instead of grouped into an array. I tried this:

$variable = array_chunk($matches[1],1);

with no success, it just prints “Array”. any help would be great things. I will post in a new question if I don’t get a response.

  • 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-28T15:22:43+00:00Added an answer on May 28, 2026 at 3:22 pm

    This is how you would escape the regex:

    foreach (glob("template/*.php") as $fn) {
    
        $file = file_get_contents($fn);
    
        preg_match_all("#\{\('(\w+)'\)}#", $file, $matches);   
    
        print_r($matches);
    
    }
    

    Eugen has shown how to match the PHP/PI <? tags and /* comment sections as well. You may just need \s* in between those.

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

Sidebar

Related Questions

I'm sorry if this question has already been answered but I couldn't find it.
I'm sorry if this question has been asked already, but I couldn't find it
Sorry if this question has already been answered but I can't find an answer.
Sorry if this question has already been answered, and sorry if it's too subjective
sorry if this question has already come up but I couldn't find anything that
Sorry if this has been answered already, but I could not find an appropriate
This has probably been asked already - if so sorry! I couldn't find it.
Sorry if this question is answered already, but I didn't find a suitable answer.
I apologize if this question has been answered already, but I cannot seem to
sorry if this has already been posted but I've been through umpteen posts on

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.