<?php
$data = 'I need a script to go in and grep following inside of a file (text):
###
SOME CONTENT SNIP
local url_check =
{
GET LINES BELOW
---
["/images/one.jpg"] = true, -- timestamphere
["/images/foo.jpg"] = true, -- timestamphere
["/images/baz.jpg"] = true, -- timestamphere
---
GET LINES ABOVE
}
SOME CONTENT SNIP
##
Explode those lines to $line, $timestamp (very easy), save to array then when I need it script
should go back to file and replace content with new lines in exacly same spot, overwriting old.
';
function aleks($data){
if(ereg("local url_check =( )?(\n)?\\{(\n)?(.*)\\}", $data, $match)){
$files = $times = $lines = array();
$exp = explode("\n", $match[4]);
foreach($exp as $line){
if(ereg('^\\[(\\"|\\\')(.*)(\\"|\\\')] = (true|false), -- (.*)$', trim($line), $match)){
$files[] = $match[2];
$lines[] = $match[0];
$times[] = $match[5];
}
}
return(array('files' => $files, 'lines' => $lines, 'times' => $times));
}
}
print_r(aleks($data));
?>