SAQS (Super Awesome Query Stringing)

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

What is SAQS?

SAQS or Super Awesome Query Stringing is a PHP class which allows you to easily use and manage query strings which are delminated by forward-slashes (/).

SAQS Demo

Query string =

Variable cat =
Variable color =
Variable pill =
Variable material =

Add/Change cat = meow
Add/Change cat = woof
Add multiple variables

Remove cat
Remove multiple variables

Forward-Slashes` are safe in `/`

External Site

Installation

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

Using SAQS

Once you have SAQS downloaded, add the following lines to the file you wish to use SAQS in.
require_once 'class_saqs.php';

//Init SAQS
if(!isset($saqs))
{
    $saqs = new saqs;
}
The grave accent (`) can be used to enclose mutliple values containing forward-slashes. For example:
echo $saqs->set_qstr_value('cat', '`this/contains/slashes`');

Methods

The following methods are avaible through the SAQS class.
$saqs->get_qstr();
Returns the current query string as a un-urldecoded string.
$saqs->get_qstr_value(string $variable);
Returns the value of the $variable.
$saqs->set_qstr_value(mixed $variable, mixed $value);
Return the current query string modified with the $variable and $value passed

Example Script

<?php
error_reporting
(E_ALL);
require_once 
'class_saqs.php';

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

//Get the current query string.
echo 'Query string = '.$saqs->get_qstr()."<br><br>\n";

//Get a specific (cat) variable.
echo 'Variable <i>cat</i> = '.$saqs->get_qstr_value('cat')."<br>\n".
     
'Variable <i>color</i> = '.$saqs->get_qstr_value('color')."<br>\n".
     
'Variable <i>pill</i> = '.$saqs->get_qstr_value('pill')."<br>\n".
     
'Variable <i>material</i> = '.$saqs->get_qstr_value('material')."<br><br>\n";

//Add/Change a variable (cat) to the query string.
echo '<a href="'.$_SERVER['SCRIPT_NAME'].$saqs->set_qstr_value('cat''meow').'">Add/Change cat = meow</a><br>';

//Add/Change a variable (cat) in the query string.
echo '<a href="'.$_SERVER['SCRIPT_NAME'].$saqs->set_qstr_value('cat''woof').'">Add/Change cat = woof</a><br>';

//Add multiple variables (color, pill, and material) to the query string.
$variable_value_array = array('color' => 'blue''pill' => 'lithium''material' => 'plastic');
echo 
'<a href="'.$_SERVER['SCRIPT_NAME'].$saqs->set_qstr_value($variable_value_array).'">Add multiple variables</a><br><br>';

//Remove a variable (cat) from the query string.
echo '<a href="'.$_SERVER['SCRIPT_NAME'].$saqs->set_qstr_value('cat''').'">Remove cat</a><br>';

//Remove multiple variables (color, pill, and material) from the query string.
$variable_value_array = array('color' => '''pill' => '''material' => '');
echo 
'<a href="'.$_SERVER['SCRIPT_NAME'].$saqs->set_qstr_value($variable_value_array).'">Remove multiple variables</a><br><br>';

//Using the grave accent and forward-slashes
echo '<a href="'.$_SERVER['SCRIPT_NAME'].$saqs->set_qstr_value('cat''`this/contains/slashes`').'">Forward-Slashes` are safe in `/`</a><br><br>';

//Link to another site with this query string
echo '<a href="http://example.com/index.php'.$saqs->get_qstr().'" target="_blank">External Site</a><br>';
?>
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?

Contact me