Current location: Hot Scripts Forums » Programming Languages » PHP » How To Open HTML File & Edit Once a Day


How To Open HTML File & Edit Once a Day

Reply
  #1 (permalink)  
Old 12-13-04, 04:34 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
How To Open HTML File & Edit Once a Day

I want some code that can open an html file like "index.html" and replace all the text between some set comments like <!-- Start Here --!> and ends at <!-- End Insert Here--> like amany guestbooks do. Example:
<!-- Start Here --!>
Yesterday's results
<!-- End Insert Here-->

with
<!-- Start Here --!>
today's results
<!-- End Insert Here-->
I will be drawing the text from a mysql database that is a list of results. I know we use fopen() & fclose() to open & close a file according to what I read but not really sure about the best way to approach this. I thought about croning it. BUt not sure about how to delete all text in between the 2 comments first.

I think I would start with
PHP Code:

$fp fopen("index.html","r+"); 

// r+ being opening the file to read and write

//  2nd Step: How do I find the <!-- Start Here --!> code 
//  in the file and delete it all up to the 
//  <!-- End Insert Here--> code?

//  3nd Step: How do I insert the new results output within
// the <!-- Start Here --!> to <!-- End Insert Here--> code?

// close file
fclose("$fp"); 
I want the entire index page to stay the same but for the text between the comments to change...
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-13-04, 04:55 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
File_get_contents for file contents to variable..

Then, preg replace <!-- blah -->(*.?)<!-- End Blah --> with new result, same var as file_get_contents, then fwrite
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-13-04, 05:03 PM
feha feha is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Try this:
Code:
<?
//By www.vision.to

$new_text="HELLO BABY!";

$Text="
NOT HEADER
<!-- Start Here --!>
CHANGE ME!
<!-- End Insert Here-->
NOT FOOTER
";
$Text =preg_replace("/\<!-- Start Here --!>(.+?)\<!-- End Insert Here-->/is",$new_text,$Text);
echo  $Text;
?>
__________________
www.flashwebshop.org/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 05:03 AM
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Server open file altafingar ASP.NET 1 10-20-04 01:12 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM


All times are GMT -5. The time now is 07:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.