inject php code into html file

Posted on 2005-04-18
Last Modified: 2013-12-16
i have alot of html file need to edit , only insert <?php include "header.php";?> in every html file, this file in my_html folder , is there any quick way to do that , than open every file just for doing that . administrator not allow using mod_layout .

thanks in advance
Question by:hendri2
    LVL 49

    Accepted Solution

    Multifile text editors like UltraEdit often also support search and replace through multiple files. The files which can be searched thru are either opened, or located in a directory. Possibly the tool you are already using also supports this kind of s&r.

    LVL 14

    Expert Comment

    Sorry to drop in, but I thought this would help elaborate:

    The way I usually do this type of replace is to ask my editor to search and replace through every file in my directory. I use DWMX2004, but as Roonaan mentioned, any multi-file editor will do.

    Assuming I want header.php to be included as the first line after the <body> opening tag in every page:

    I would search for:

    ... and replace with:

    <?php include "header.php"; ?>'

    Don't need to give me any points, but this may not have been as obvious as it seems.
    LVL 7

    Expert Comment

    You can also use sed/perl to do this, eh?

    Author Comment

    can u gave me sed/perl code for that
    LVL 20

    Assisted Solution

    you could also do it in php (this function doesn't check to see if the line is already there):
    be very careful with this.

    $directory = "c:/myphp/"
    echo '<TABLE>';
    echo '<TR>';
    if($dir_handle = @opendir($directory)) {  //I know @ code is a bad idea, but here I don't see a way of circumventing it
        while($file = readdir($dir_handle))
          if($file !== "." && $file !== ".."){
              if (($count % 4) == 0) { echo '<TR style="width:100%;height:104px;padding-left:10px">'; }
                echo '<TD>';
                    $myfile = file_get_contents($file);
                    $myfile = '<?php include "header.php"; ?>' . $myfile;
                   echo '</TD>' . "\n";

    LVL 3

    Assisted Solution

    Use Extended Search & Replace in Macromedia Homesite.

    search for <html>

    replace with <?include "header.php"?> <html>

    Find where : In Folder (direct to your folder where all the files exits)
    File Type : *.html (or whatever you like)

    Pressing Replace button will do the rest.

    Now your life become very very easy.

    Hope this help.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now