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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:02:23+00:00 2026-05-13T11:02:23+00:00

The setup: I have a standard .php file (index.php) that contains two includes, one

  • 0

The setup:

I have a standard .php file (index.php) that contains two includes, one for header (header.php) and one for footer (footer.php). The index.php file looks like this:

index.php

<?php
include header.php;
?>

<h2>Hello</h2>
<p class="editable">Lorem ipsum dolar doo dah day</p>

<?php
include footer.php;
?>

header.php like this:

<html>
<head>
<title>This is my page</title>
</head>
<body>
<h1 class="editable">My Website rocks</h1>

and footer .php like this:

<p>The end of my page</p>
</body>

I am writing a PHP script that allows you to edit any of the “.editable” items on a page. My problem is that these editable regions could appear in any included files as well as the main body of index.php.

My php code is grabbing the index.php file with file_get_contents(); which works well. I am also able to edit and save any “.editable” regions in index.php.

My issue:

I have been unable to find a way of “finding” the includes and parse through those for “.editable” regions as well. I am looking for suggestions on how I would work through all the includes in index.php – checking them for editable regions. Would I need to use regular expressions to find “include *.php”? I am unsure of where to even start…

For those of you who may wish to see my PHP code. I am making use of the PHP class: [link text][1] which allows me to write code like:

// load the class and file
$html = new simple_html_dom();
$html->load_file("index.php");

// find the first editable area and change its content to "edited"  
$html->find('*[class*=editable]', 0)->innertext = "Edited";

// save the file
$html->save(index.php);

[1]: http://simplehtmldom.sourceforge.net/manual_api.htm simple php dom parser


UPDATE

I have been playing around with regular expressions to try and match the includes. I am pretty rubbish at regex but I think I am getting close. Here is what I have so far:

$findinclude = '/(?:include|include_once|require|require_once)\s*(?:[a-z]|"|\(|\)|\'|_|\.|\s|\/)*(?=(?:[^\<\?]|[^\?\>])*\?>)/i';

This matches fairly well although it does seem to return the odd ) and ‘ when using preg_match. I am trying to add a bit of security into the regex to ensure it only matches between php tags – this part: (?=(?:[^\<\?]|[^\?>])*\?>) – but it only returns the first include on a page. Any tips on how to improve this regular expression? (I have been at it for about 6 hours)

  • 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-13T11:02:23+00:00Added an answer on May 13, 2026 at 11:02 am

    Ok, I finally worked it out. If anyone is looking to find any include, include_once, require, require_once in a .php file then you can use the following regular expression with a php function like preg_match_all.

    '/(?:include|include_once|require|require_once)\s*(?:[a-z]|"|\(|\)|\'|_|\.|\s|\/)*(?=(?:[^\<\?])*\?>)/i';
    

    This looks for any includes etc within tags. Referencing this back to my original example. My code looks like this:

    $html = new simple_html_dom();
    $html->load_file("index.php");
    
    $findinclude = '/(?:include|include_once|require|require_once)\s*(?:[a-z]|"|\(|\)|\'|_|\.|\s|\/)*(?=(?:[^\<\?])*\?>)/i';
    
    if (preg_match_all($findinclude, $html,$includes)):
    
        // shift the array to the left
        $incfiles = $includes[0];
        $i = 0;
    
        // then loop through the includes array and print our filename
        foreach ($incfiles as $inc) {
           print basename(preg_replace('/[^a-zA-Z0-9\s\.\_\/]/', '', $inc)."\n");
        }
    endif;
    

    Job done! I can now work through this to edit each file as required.

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

Sidebar

Related Questions

I have a standard list view setup with backbone that looks something like below.
I have a standard php app that uses SQL Server as the back-end database.
I have a standard UINavigationController setup. One particular view displays an Edit button on
I have the standard setup of one main image and multiple thumbnails which can
I have two database connections, one that is used for most of my application
I have standard databindings setup for all my TextBoxes to an Object like this:
I have a basic Magento (PHP app, using index.php as the controller) setup on
I have a webserver setup using the standard linux, apache, mysql, php config and
A lot of web frameworks have a standard setup for generating forms with auth
So I have a fairly standard LINQ-to-Object setup. var query = expensiveSrc.Where(x=> x.HasFoo) .OrderBy(y

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.