• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2034
  • Last Modified:

inject php code into html file

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
0
hendri2
Asked:
hendri2
3 Solutions
 
RoonaanCommented:
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.

-r-
0
 
crackyCommented:
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:
'<body>'

... and replace with:

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

Don't need to give me any points, but this may not have been as obvious as it seems.
0
 
PromethylCommented:
You can also use sed/perl to do this, eh?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
hendri2Author Commented:
can u gave me sed/perl code for that
0
 
virmaiorCommented:
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">'; }
          $count++;
            echo '<TD>';
                $myfile = file_get_contents($file);
                $myfile = '<?php include "header.php"; ?>' . $myfile;
                file_put_contents($filename,$myfile);
               echo '</TD>' . "\n";

        }
    }
      closedir($dir_handle);
      }
0
 
designbaiCommented:
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.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now