{
    $filenames = scandir($folder);
    array_shift($filenames);
    array_shift($filenames);
    $items = array();
    $i = 0;
    foreach ($filenames as $title) {
        $URL = $folder . '/' . $title;
        $contents = file_get_contents($URL);
        if (preg_match('/<title>(.+)<\\/title>/', $contents, $matches) && isset($matches[1])) {
            $items['files'][$i]['filename'] = $filenames[$i];
            $items['files'][$i]['contents'] = $contents;
            $items['titles'][$i]['regex'] = "/(\\b)(" . $matches[1] . ")(\\b)/ui";
            $items['titles'][$i]['filename'] = $filenames[$i];
        }
        $i++;
    }
    return $items;
}
$files = get_titles_and_content($folder);
foreach ($files['files'] as $file) {
    foreach ($files['titles'] as $title) {
        $file['contents'] = linker($file['contents'], $title['regex'], $title['filename'], $max);
    }
    $newfile = fopen($newfolder . "/" . $file['filename'], 'w') or exit;
    fwrite($newfile, $file['contents']);
    fclose($newfile);
}
?>
Done!
Esempio n. 2
0
function paginate($a, $pg, $adt = '')
{
    $i = 0;
    $pgs = explode(',', $a[$pg . 's']);
    $path = '/archive/';
    do {
        $path .= current($a) . '/';
    } while (next($a) && $pg != key($a));
    foreach ($pgs as $val) {
        if ($val == $a[$pg]) {
            $prev = isset($pgs[$i - 1]) ? $pgs[$i - 1] : '';
            $next = isset($pgs[$i + 1]) ? $pgs[$i + 1] : '';
            break;
        }
        $i++;
    }
    return '<div class="ctrl rht"><ul class="pagination"><li>' . linker($prev ? $path . $prev : '#', '', 'btn') . '</li><li><span>' . ($i + 1) . ' of ' . count($pgs) . '</span></li><li>' . linker($next ? $path . $next : '#', '', 'btn') . '</li></ul>' . linker(substr($path, 0, -1), 'Up', 'btn brd lev') . $adt . '</div>';
}