I have written a PHP script that takes copies of external webpages and stores them on a local fileserver.
The URLs of the webpages always follow the same pattern, in that they have the same domain prefix and the same arguments as a suffix... it's just the bit in the middle that changes (the 'widgetid').
Here it is, in all it's glory...
(don't laugh... it took me four hours to write after copious reading of w3schools... haha)
- Code: Select all
<?php
/* widget url variables */
$wyoprefix = 'http://www.example.com/widget/view?widgetId=';
$wyosuffix = '&geoTypeId=1&geoIds=0001&useComp=true&format=html';
$widgets_list = array(
"WIDGET_0000001",
"WIDGET_0000002"
);
$widgets_count = count($widgets_list);
for ($i = 0; $i < $widgets_count; $i++) {
$fullstring = $wyoprefix . $widgets_list[$i] . $wyosuffix;
/* saved files location on server */
$destination = 'tables/' . $widgets_list[$i] . '.html';
file_put_contents($destination, file_get_contents($fullstring));
}
?>
It works well enough and I intend to automate it to run once a week. However, as the number of instances in the array is likely to grow substantially, I would prefer to keep the array values in a separate CSV file for ease of maintenance and addition.
I've spent the last few hours trying to use different techniques that I've seen listed (SplFileObject and others), but I can't make it work.
Can anyone give me a few pointers?
Thanks,
tambo


