<?php
/*
*******************************************************************************
FiForms -- A collection of PHP classes designed
to facilitate rapid development of web-database software
Copyright (C) 2003-2008 Daniel McFeeters
This library 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 2 of the License, or (at your option) any later version.
This library 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.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The original author of this library can be contacted at the following
address:
Daniel McFeeters
182 Baker Rd.
Faubush, KY 42544-6526
email: databases [at] fiforms [dot] org
http://www.fiforms.org/
*******************************************************************************
FiForms_fillVars.inc.php
Fill Variables function
*******************************************************************************
*/
/* ?><code><?php */
$fillvars_iteration_count = 0;
function fillVars($varArray, $varString, $html = FALSE)
// substitutes variable names in $varString (in the form %variable%)
// with their corresponding values in $varArray
{
$GLOBALS['fillvars_iteration_count']++;
$vnList = array();
$vvList = array();
if(isset($varArray))
{
foreach($varArray as $varName => $varValue)
{
if(
(is_string($varValue) ||
is_null($varValue) ||
is_integer($varValue)
) &&
$varName ==
str_replace(array(' ','"','\'','(',')','`','%',',',':',';'),'',$varName)
) // check if varValue and varName is valid
{
$vnList[] = '%'.$varName.'%';
if(is_string($varValue))
{
$vvList[] = $html ? htmlentities($varValue): $varValue;
}
else
{
$vvList[] = $varValue;
}
} // if isValid
} // foreach
return(str_replace($vnList,$vvList,$varString));
}
else
{
return($varString);
} // if varArray
} // function fillVars
/* ?></code><?php */
?>