Jump to content

[SOLVED] Removing all PHP from a file


Rashy

Recommended Posts

I have hundreds of files that I need to remove all of the PHP from: I am converting from static pages to a database driven site.

 

Basic structure of each page goes like this:

 

<? 
$title = "TITLE"; 
// Some more variables that set things such as the description and keywords 

require_once('required-files/top.php'); 
// Most have just this, a few have others on a situational basis 

?> 

Content of Article 

<?php 

require_once('required-files/bottom.php'); 

?>

 

So I thought it would be pretty easy. Include the file, gather the variables (such as $title), then "reopen" the file and use preg_replace to remove the PHP. Here is my code that concerns the regex and the "warning" I am getting:

 

$pattern = "#<\?(+.?)\?>#imes";
            $fp = fopen($file,"r");
            if(!$fp){
              die("File Doesn't Open");
            } 
           $txt = fread($fp, filesize($file));
           while(preg_match($pattern, $txt)){
              $txt = preg_replace($pattern, "", $txt);
            }
            $txt = htmlentities($txt);
            echo '<div style="background-color:#eeeeee">';
            echo $txt;
            echo '</div>';

Sorry if my code is sloppy, I usually keep it nice but I am very frustrated right now. Anyways, the error I am getting:

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 4 in C:\xampp\htdocs\rashy\work\files.php on line 36

 

Now I don't even know what that error means  ;)

 

Basically what I am trying to do at this point is take that original file and store only the content into a variable so I can then store that into the database.

 

I am doing this on a dev server, just using XAMPP, PHP 5.2.2, all default settings except I did turn on ModRewrite, but I don't think that should have any effect here.

 

The ouput of echo($txt); shows me the contents of the file in question (I could copy-paste it into notepad, save it, and it would be an exact duplicate).

 

Thanks for any help  :D

 

Link to comment
Share on other sites

well the erros are self explanatory if you are up with your regex's

 

that error occurred because you had the + in (+.*) meanin more than one NOTHING - ( defines the start of a group in the string + - macth more than one so you have nothing to match more than one of.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.