Re: Example Needed
| From: | Jay Greenspan | Date: | Sat, 16 Sep 2000 18:57:35 +0000 |
| Subject: | Re: Example Needed | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17051@lists.php.net to get a copy of this message | ||
Here's what I came up with. I'd definitely test
before unleashing this on a directory that doesn't have a good
backup.
I suppose that instead of the preg_repace you could use
substr() and strpos().
-j
$str1 = "<?php
$date=\"blah\";
$page=\"page#\";
include ('../head.php3');
<a";
$str2 = "<?php
include ('../foot.php3');
?>";
$filename="/path/to/file";
$fp = fopen($filename, "r+");
$contents = fread ($fp, filesize($filename));
$new_contents = preg_replace("/^.*?<a/s", $str1, $contents);
$new_contents = str_replace("</body>", "", $new_contents);
$new_contents = str_replace("</html>", "", $new_contents);
$new_contents .= $str2;
rewind($fp);
fwrite($fp, $new_contents);
fclose($fp);
__________
Hello. I would like to create a php script or something would would take a
file and delete everything before the first "<a". Then it should add
<?php
$date="blah";
$page="page#";
include ('../head.php3');
?>
to the top of the file.
It should also delete the last two lines or
<body>
</html>
It should then append
<?php
include ('../foot.php3');
?>
to the bottom of the file. I have no idea how to go about this, so any help
would be greatly appreciated. Thank you!