<?php
include "class.cache.php";
//SAMLPE 1
// starting caching with gzip
$cache = new Cache;
// there is no need to call neither $cache->cacheFlush(); nor __destructor
// to call destructor yourself write $cache=NULL;
//SAMPLE 2
// starting caching with gzip to file attachedfile.xml.gz
$cache = new Cache(FALSE);
$cache->cacheStart('makeGZip', array(5,'attachedfile','xml'));
// you have no need to send any headers
//SAMPLE 3
// Highlight text
$_GET['sth'] = "string to highlight";
$cache = new Cache;
$cache->cacheStart('makeHighlight', array($_GET['sth'],'i','ff0000')); // tag & color
$cache->cacheStart('makeHighlight', array('some','b','00ff00')); //you can use this funñ twice and more
echo 'I want to highlight some string'; // text
$cache->cacheFlush();
//I want <i style="background-color:#ff0000">to</i> <i style="background-color:#ff0000">highlight</i> <b style="background-color:#00ff00">some</b> <i style="background-color:#ff0000">string</i>
//SAMPLE 4
$cache = new Cache(FALSE);
$cache->cacheStart('makeGZip', array(5,'attachedfile','xml'));
$gpc->define('highlight','TXT','G');
$cache->cacheStart("makeHighlight", "link");
echo "<a href='/index.php?a=b&c=d&e=f&g=h&i=j#anchor'>link</a>"; // 5 arguments only
echo "<a onclick=\"document.location='index.php?a=b&c=d&e=f&g=h&i=j#anchor'\">link</a>"; // JS compatible
echo "<img src='pat/to/img.jpg'>"; // images too
//SAMPLE 5
/*
rewrite engine
URL : onclick=\"document.location='/list_of_pages.php?a=b&c=d&e=f&g=h&i=j#three words anchor'\"
REGEXP : #(action|href|src|location|background)=(\"|') (\/)? ([\/\.a-z0-9_-]+) \.(\w+) \?? (?: ([a-z0-9\[\]]+) = (\w+?))? (?: \& ([a-z0-9\[\]]+) = (\w+?))? (?: \& (\S*?))? (\#[-a-z0-9_\ ]*)?(\"|')#six
CALL BACK FUNC : _makeFolderURL
PATTERNS:
(action|href|src|location|background) ~ location
= ~ =
(\"|') ~ '
(\/)? ~ /
([\/\.a-z0-9_-]+) ~ list_of_pages
\. ~ .
(\w+) ~ php
\?? ~ ?
(?: ([a-z0-9\[\]]+) = (\w+?))? ~ a=b
-->([a-z0-9\[\]]+) ~ a
-->= ~ =
-->(\w+?) ~ b
(?: \& ([a-z0-9\[\]]+) = (\w+?))? ~ &c=d
-->\& ~ &
-->([a-z0-9\[\]]+) ~ c
-->= ~ =
-->(\w+?) ~ d
(?: \& (\S*?))? ~ &e=f&g=h&i=j
-->\& ~ &
-->(\S*?) ~ &e=f&g=h&i=j
(\#[-a-z0-9_\ ]*)? ~ #three words anchor
(\"|') ~ '
count of patterns is 12
FUNCTION
$string = $args[1]."=".$args[2]."http://".$_SERVER['SERVER_NAME']; // absolute path // location='http://localhost
$string .= $_SERVER['SERVER_PORT']!= 80 ? ":".$_SERVER['SERVER_PORT']."/" : "/"; // port if it is not 80 // /
$string .= ($args[4]!="index") ? $args[4] : ""; // if it is index leave empty // list_of_pages
$string .= ($args[5]!="php") ? ".".$args[5] : (($args[4]!="index") ? "/" : ""); // if extention is php rewrite to subdir // /
$string .= $args[7] ? $args[7]."/" : "" ; // first argument of query sting // b/
$string .= $args[9] ? "?".$args[8]."=".$args[9] : ""; // second argument of query string // ?c=d
$string .= $args[10] ? "&".$args[10] : ""; // all other arguments // &e=f&g=h&i=j
$string .= $args[11] ? $args[11] : ""; // anchor // #three words anchor
$string .= $args[12]; // '
.HTACCESS
Options FollowSymLinks -Indexes -Multiviews
RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+)/?$ $1.php?%{QUERY_STRING} [NC,L]
RewriteRule ^([a-z]+)/([a-z0-9]+)/?$ $1.php?act=$2&%{QUERY_STRING} [NC,L]
# act is name of first query argument
*/
//SAMPLE 6
/*
rewrite engine
URL : onclick=\"document.location='/list_of_pages.php?a=b&c=d&e=f&g=h&i=j#three words anchor'\"
REGEXP : #(action|href|src|location|background)=(\"|') (\/)? ([\/\.a-z0-9_-]+) \.(\w+) \?? (?: ([a-z0-9\[\]]+) = (\w+?))? (?: \& ([a-z0-9\[\]]+) = (\w+?) (?: \& ([a-z0-9\[\]]+) = (\w+?) (?: \& ([a-z0-9\[\]]+) = (\w+?) (?: \& ([a-z0-9\[\]]+) = (\w+?)?)?)?)?)? (\#[-a-zà-ÿ0-9_\ ]*)?(\"|')#six
CALL BACK FUNC : _makeFolderURL
PATTERNS:
(action|href|src|location|background) ~ location
= ~ =
(\"|') ~ '
(\/)? ~ /
([\/\.a-z0-9_-]+) ~ list_of_pages
\. ~ .
(\w+) ~ php
\?? ~ ?
(?: ([a-z0-9\[\]]+) = (\w+?))? ~ a=b
-->([a-z0-9\[\]]+) ~ a
-->= ~ =
-->(\w+?) ~ b
(?: \& ([a-z0-9\[\]]+) = (\w+?) ~ &c=d
-->(?: \& ([a-z0-9\[\]]+) = (\w+?) ~ &e=f
-->-->(?: \& ([a-z0-9\[\]]+) = (\w+?) ~ &g=h
-->-->-->(?: \& ([a-z0-9\[\]]+) = (\w+?) ~ &i=j
?)?)?)?)?
(\#[-a-z0-9_\ ]*)? ~ #three words anchor
(\"|') ~ '
count of patterns is 17
FUNCTION
$string = $args[1]."=".$args[2]."http://".$_SERVER['SERVER_NAME'];
$string .= $_SERVER['SERVER_PORT']!= 80 ? ":".$_SERVER['SERVER_PORT']."/" : "/";
$string .= ($args[4]!="index") ? $args[4] : "";
$string .= ($args[5]!="php") ? ".".$args[5] : (($args[4]!="index") ? "/" : "");
for ($i=6;$i<15;$i+=2) // without arrays
$string .= $args[$i+1]==="" ? "" : $args[$i+1]."/"; // query string
$string .= $args[16] ? $args[16] : ""; // #anchor
$string .= $args[17]; // "|' right bracket
the same like in previous func but count of arguments of query sting 5
for ($i=6;$i<15;$i+=2) // from 6-7 to 14-15
$string .= $args[$i+1]==="" ? "" : $args[$i+1]."/";
you can replace empty string ("") with "_" to know that this argument is empty but next in not
or more
$string .= $args[$i+1]==="" ? ($args[$i+3]?"":"_") : $args[$i+1]."/";
.HTACCESS
.HTACCESS
Options FollowSymLinks -Indexes -Multiviews
RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+)/?(([a-z0-9]+)/?(([a-z0-9]+)/?(([a-z0-9]+)/?(([a-z0-9]+)/?(([a-z0-9]+)/?)?)?)?)?)?$ $1.php?param[0]=$3¶m[1]=$5¶m[2]=$7¶m[3]=$9¶m[4]=$11 [NC,L]
*/
?>
|