Rashy Posted July 17, 2007 Share Posted July 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 17, 2007 Share Posted July 17, 2007 $pattern = "#<\?(php)?(.)*?\?>#imes"; Quote Link to comment Share on other sites More sharing options...
Rashy Posted July 17, 2007 Author Share Posted July 17, 2007 Yup. that worked perfectly. Is there a place where I could find out what warnings like that actually mean? I couldn't find anything about that from Googlework. And thank you for your help! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 17, 2007 Share Posted July 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.