SAQS (Super Awesome Query Stringing)

This article will introduce the SAQS PHP class and outline the proper procedures for its use.

What is SAQS? #Top

Super Awesome Query Stringing or SAQS for short, is a PHP class which allows you to easily create and manage query strings which are delimitated by foreslashes (/). Through SAQS it is possible to manage foreslash-delimited query strings without nasty hacks to Apache through mod_rewrite. SAQS also has the benefit of also working on Microsoft's IIS as well as Nginx.

SAQS Demo #Top

Query String   = 

Variable one   = 
Variable two   = 
Variable three = 
Variable four  = 

Set "three" to meow
Set "three" to woof
Foreslashes(/) are ignored in backticks (`).
Unset variable "three"

Set variables one, two, and four to fish,blue and red
Unset variables one, two, and four

External Site (w/ query string)

Installation #Top

  1. Download SAQS.
  2. Extract the archive.
  3. Read: Using SAQS.

Using SAQS #Top

Once SAQS has been downloaded, copy the file "class_saqs.php" to the project directory and add the following lines to the file(s) you wish to use SAQS:
require_once 'class_saqs.php';

//Init SAQS
if(!isset($saqs)) {
    $saqs = new saqs;
}

Methods

The following methods are available through the SAQS class.
string $saqs->get_qstr ( void )
Returns the current query string unmodified.
string $saqs->get_qstr_value ( string $variable )
Returns the value of the key $variable.
string $saqs->set_qstr_value ( mixed $variable, mixed $value )
Returns the current query string with the key $variable being set to the value of $value.

Backticks

At times it may be required to assign values to keys which contain one or more foreslashes. To accomplish this and not have the foreslashes interpreted as key/value pairs, the value can be surrounded in backticks (`):
echo set_qstr_value('three','`this/contains/slashes`');

Example Script #Top

<?php
error_reporting(E_ALL);
require_once 'class_saqs.php';
$SSN = $_SERVER['SCRIPT_NAME'];

if(!isset($saqs)) {
    $saqs = new saqs;
}

echo <<<HD
<pre>
Query String   = {$saqs->get_qstr()}

Variable <b>one</b>   = {$saqs->get_qstr_value('one')}
Variable <b>two</b>   = {$saqs->get_qstr_value('two')}
Variable <b>three</b> = {$saqs->get_qstr_value('three')}
Variable <b>four</b>  = {$saqs->get_qstr_value('four')}
</pre>
<p>
<a href="{$SSN}{$saqs->set_qstr_value('three', 'meow')}">Set "three" to meow</a><br>
<a href="{$SSN}{$saqs->set_qstr_value('three', 'woof')}">Set "three" to woof</a><br>
<a href="{$SSN}{$saqs->set_qstr_value('three', '`this/contains/slashes`')}">
Foreslashes<sup>(/)</sup> are ignored in backticks <sup>(`)</sup>.</a><br>
<a href="{$SSN}{$saqs->set_qstr_value('three', '')}">Remove variable "three"</a>
</p>
<p>
<a href="{$SSN}{$saqs->set_qstr_value( array('one' => 'fish', 'two' => 'blue', 'four' => 'red') )}">
Set variables one, two, and four to fish,blue and red</a><br>
<a href="{$SSN}{$saqs->set_qstr_value( array('one' => '', 'two' => '', 'four' => '') )}">
Unset variables one, two, and four</a>
</p>
<p>
<a href="http://example.com/id.php{$saqs->get_qstr()}" target="_blank">External Site (w/ query string)</a>
</p>
HD;
?>

Copyright © 2007, 2008 Matthew Headlee

SAQS (Super Awesome Query Stringing) is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

SAQS (Super Awesome Query Stringing) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Questions or Feedback? #Top

Contact me