Regular Expressions assistance needed

mcpilot1
mcpilot1 used Ask the Experts™
on
I have a website consisting of dozens, maybe a hundred, html files. Each of these has a date such as "Last Updated: June 3, 2014"

I want to go through and change all of those dates to today's date without having to manually do it. Regular expressions is most likely the best route. If someone could assist with the proper code, that would be great as I am not convfersant in the programming of regular expressions.

Dreamweaver is the platform.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Off the top of my head - here is a small PHP script that should do it. Run it in a folder with COPIES of your files you want to update.
NB: COPY
<?php
// GET ALL HTML FILES
$files = glob('*.html');

// SET OUR NEW DATE STRING
$replace = "Last Updated: " .  date('M d, Y');

// LOOP THROUGH FILES
foreach($files as $f) {
   // LOAD THE FILE CONTENTS
   $data = file_get_contents($f);

   // DO THE REPLACE
   $data = preg_replace('/Last Updated:(.*?) (\d\d?), (\d\d\d\d)/', $replace, $data);

   // PUT THE DATA BACK
   file_put_contents($f, $data);
}

Open in new window

Author

Commented:
This worked perfectly. Thank you!
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial