SSI - Regular Expressions

| No Comments

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

<!--#if expr="$QUERY_STRING = /src=([^;]*)/" --><!--#set var="picture" value="$1" --><!--#endif -->

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

<!--#if expr="$picture = /([0-9][0-9][0-9][0-9])/" --><!--#set var="number" value="$1" --><!--#endif -->

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

<!--#if expr="$QUERY_STRING_UNESCAPED = /comm=([^;]*)/" --><!--#set var="comment" value="$1" --><!--#endif -->

- 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)

Leave a comment

Pages

Recent Comments

  • nickh: Daniel is right here, asleep in his bouncy chair. Very read more
  • Caroline Yates: You should keep cight for personal stuff and funny stuff read more
  • Meri: Whoops, the first comment was meant to go to your read more
  • Meri: Main thing that I would say is before you give read more
  • Meri: Have you tried the daily posting feature? You can set read more
  • Carlos Contreras: Would you like to see my work? www.3dreamagic.com bye read more
  • kyle: hey way better cricket game out there!! www.stickcricket.com read more
  • andrew tomlinson: this game is wicked and adictive thanks for it. read more
  • Jay: Hello there, My name is jay,I love this game and read more
  • Mayuresh Kadu: Found you via geourl. Seems we live a few minutes read more
OpenID accepted here Learn more about OpenID

Adverts

Find recent content on the main index or look in the archives to find all content.