SSI – Regular Expressions

转载,来自:http://www.cight.com/spareparts/archives/000269.shtml

Since the advent of Apache 2.0.x you have been able to do regular expressions in apache ssi. Meaning less reliance for me at least on .htaccess files and mod_rewrite.

This has lead me to be able to quickly make template files that pass the query string in multiple parts to the page to dynamically change the content.

Hence we have the Benjamin Gallery and examples of the query string in use (bits echoed in red)-

http://www.cight.com/benjamin/gallery/august/ tmpl.shtml?src=big/big_img_2421.jpg; comm=Flashdance%20Benjamin

Using code as follows

– find the src= bit find and capture what is after it, until you find a ; then set that as a variable called picture.

– take the pciture variable now created, and look in it for 4 digits, save that as a variable called number.

– find the comm= bit find and capture what is after it, until you find a ; then set that as a variable called comment. Unfortunately if you use punctuation this ends up escaped if you then echo it, meaning ? becomes \?. And a weirdness in apache won’t let you get rid of the \.

Then you can use the variables you have to put comments on the page, link to the larger version (like in the example) and back without chnaging template.

Also it makes the gallery page very easy to create, you just put in the urls of the images and wrap template code to each one (go view source)