Functions within functions not sending parameters?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Functions within functions not sending parameters?

Post by JAB Creations »

The PHP below works out of the box except the multifunction function. Essentially my question is why are the parameters in the functions (within the parent function) not being set?

When I validate manually calling each function individually on lines 96~100 it works fine. However when I attempt to echo any return on the "super" function I get the error 'Empty regular expression' which I understand what it is and how it would be cause, yet I'm not sure why having the functions within a parent function would strip the parameters from the child functions?

Keep in mind I've made it easy to spot which text input contains the invalid data (just add another 0-f hex value to validate it of course (CSS color value)).

So validation works fine save when I attempt to group all the functions in to a single function.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>PHP Serverside Validation of CSS post data</title>
<style type="text/css">
body,html {font-family: monospace;}
b {color: #00f;}
b.bad {color: #f00;}
b.good {color: #0f0;}
div {outline: #f00 solid 1px;}
div.overflow {float: left; font-size: 12px; height: 240px; margin: 4px; overflow: auto; width: 25%;}
form {float: left; width: 400px;}
form input {font-size: 10px; width: 60px;}
</style>
</head>
<body>
 
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset>
<div>
<input name="ce000" value="body" />
<input name="ce001" value="444" />
<input name="ce002" value="11/002" />
<input name="ce003" value="00f" />
<input name="ce004" value="00f" />
</div>
<div>
<input name="ce010" value="h2, h2, h3, h4" />
<input name="ce011" value="transparent" />
<input name="ce012" value="none" />
<input name="ce013" value="1f1" />
<input name="ce014" value="115" />
</div>
<div>
<input name="ce020" value="div" />
<!-- Default Value below is invalid, add an extra digit (0-F Hex) to validate -->
<input name="ce021" style="background-color: #000; border-color: #f0f; color: #fff;" value="55555" />
<input name="ce022" value="01/002" />
<input name="ce023" value="5f6" />
<input name="ce024" value="5f6" />
</div>
<div>
<input name="ce030" value="span" />
<input name="ce031" value="7d6" />
<input name="ce032" value="" />
<input name="ce033" value="" />
<input name="ce034" value="" />
</div>
<br style="clear: both;" />
<input style="display: block; width: 60%;" type="submit" value="Validate Form Data" />
</fieldset>
</form>
 
<?php
function super_validate()
{
if (validate_clientside_array($regex_0_selectors,'0') != 'invalid'
&& validate_clientside_array($regex_1_colors,'1') != 'invalid'
&& validate_clientside_array($regex_2_bgimages,'2') != 'invalid'
&& validate_clientside_array($regex_1_colors,'3') != 'invalid'
&& validate_clientside_array($regex_1_colors,'4') != 'invalid'
) {return 'invalid';}
}
 
function validate_clientside_array($regex, $position)
{
$item = '/'.$position.'$/';
 //echo 'parameter 1 = <b>'.$regex.'</b><br />';
 //echo 'parameter 3 = <b>'.$position.'</b><br /><br />';
 
  foreach($_POST as $key => $value)
  if (preg_match($item, $key))
  {
  if ($validity != '1')
   {
   //if (preg_match($regex, $value)) {echo ' <b class="good">'.$key.' = '.$value.'</b> is a <b class="good">match</b>!</b><br />'."\n";}
   //else {echo '<b class="bad">'.$key.' == '.$value.'</b> not a <b class="bad">match</b>!</b><br />'; $validity = '1'; return 'not valid';}
   if (!preg_match($regex, $value)) {return 'invalid';}
   /*return false;*/
  }
 }
}
 
$regex_0_selectors = '/([0-9A-z]([#|.|,|:][0-9A-z]){0,10})?$/';
$regex_1_colors    = '/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/';
$regex_2_bgimages  = '/^(([0-9]{2})\/([0-9]{3})|none)?$/';
 
echo '<b> R E S U L T = </b>'.super_validate();
echo '<br style="clear: both;" />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_0_selectors,'0').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_2_bgimages,'2').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'1').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'3').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'4').'<br />';
 
if (validate_clientside_array($regex_0_selectors,'0') != 'invalid'
&& validate_clientside_array($regex_1_colors,'1') != 'invalid'
&& validate_clientside_array($regex_2_bgimages,'2') != 'invalid'
&& validate_clientside_array($regex_1_colors,'3') != 'invalid'
&& validate_clientside_array($regex_1_colors,'4') != 'invalid'
) {echo '<br />The array contains <b class="good">only valid data</b>.';}
else {echo '<br />The array <b class="bad">contains invalid data</b>!';}
 
?>
</body>
</html>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Functions within functions not sending parameters?

Post by Christopher »

It is hard to know where to start with code like this. You have a lot of undefined variables in both functions and problems throughout the code. I have followed from a distance several of your recent threads. itd seems that you are having some problems with some of the basics of structured and modular programming. Programming is a slightly counter-intuitive craft. Perhaps is might make sense to work through coding this page from scratch?
(#10850)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Functions within functions not sending parameters?

Post by JAB Creations »

I did create an example from scratch to ensure I could use parameters with functions if those functions where inside a parent function...

Code: Select all

<?php
function func1($a, $b)
{
$c = '1';
if ($a === $c && $b === $c) {return 'match 1<br />';}
}
 
function func2($a, $b)
{
$c = '1';
if ($a === $c && $b === $c) {return 'match 1<br />';}
}
 
function func3($a, $b)
{
$c = '1';
if ($a === $c && $b === $c) {return 'match 1<br />';}
}
 
function all() 
{
echo func1('1','0');
echo func2('1','1');
echo func3('1','2');
}
 
echo all();
?>
I'll modify it to start including the regex and post my most advanced successful working example and the first example where I encounter reproduction of the error message.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Functions within functions not sending parameters?

Post by Christopher »

JAB Creations wrote:I did create an example from scratch to ensure I could use parameters with functions if those functions where inside a parent function...
I don't understand what "if those functions where inside a parent function" means from looking at your code?
JAB Creations wrote:I'll modify it to start including the regex and post my most advanced successful working example and the first example where I encounter reproduction of the error message.
Again ... I think you are on to that stuff, but you don't have the basics clear. That's why I suggested that we walk through solving something like this from scratch so you get the basics right.
(#10850)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Functions within functions not sending parameters?

Post by JAB Creations »

Ah-HA! It was tricky (and I'm a dumbass for editing the wrong file while gnawing with the desired approach) but I figured it out...sort of. :mrgreen:

It's some sort of reverse-variable scope. It seems that variables defined outside of a function should probably be passed as parameters in the situation I'm dealing with.

I commented out lines 57~63 and manually entered the regex int he code below and everything worked fine...

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>PHP Serverside Validation of CSS post data</title>
<style type="text/css">
body,html {font-family: monospace;}
b {color: #00f;}
b.bad {color: #f00;}
b.good {color: #0f0;}
div {outline: #f00 solid 1px;}
div.overflow {float: left; font-size: 12px; height: 240px; margin: 4px; overflow: auto; width: 25%;}
form {float: left; width: 400px;}
form input {font-size: 10px; width: 60px;}
</style>
</head>
<body>
 
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset>
<div>
<input name="ce000" value="body" />
<input name="ce001" value="444" />
<input name="ce002" value="11/002" />
<input name="ce003" value="00f" />
<input name="ce004" value="00f" />
</div>
<div>
<input name="ce010" value="h2, h2, h3, h4" />
<input name="ce011" value="transparent" />
<input name="ce012" value="none" />
<input name="ce013" value="1f1" />
<input name="ce014" value="115" />
</div>
<div>
<input name="ce020" value="div" />
<!-- Default Value below is invalid, add an extra digit (0-F Hex) to validate -->
<input name="ce021" style="background-color: #000; border-color: #f0f; color: #fff;" value="55555" />
<input name="ce022" value="01/002" />
<input name="ce023" value="5f6" />
<input name="ce024" value="5f6" />
</div>
<div>
<input name="ce030" value="span" />
<input name="ce031" value="7d6" />
<input name="ce032" value="" />
<input name="ce033" value="" />
<input name="ce034" value="" />
</div>
<br style="clear: both;" />
<input style="display: block; width: 60%;" type="submit" value="Validate Form Data" />
</fieldset>
</form>
 
<?php
function super_validate()
{
/*
if (validate_clientside_array($regex_0_selectors,'0') != 'invalid'
&& validate_clientside_array($regex_1_colors,'1') != 'invalid'
&& validate_clientside_array($regex_2_bgimages,'2') != 'invalid'
&& validate_clientside_array($regex_1_colors,'3') != 'invalid'
&& validate_clientside_array($regex_1_colors,'4') != 'invalid'
*/
 
if (validate_clientside_array('/([0-9A-z]([#|.|,|:][0-9A-z]){0,10})?$/','0') == 'invalid'
||
validate_clientside_array('/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/','1') == 'invalid'
||
validate_clientside_array('/^(([0-9]{2})\/([0-9]{3})|none)?$/','2') == 'invalid'
||
validate_clientside_array('/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/','3') == 'invalid'
||
validate_clientside_array('/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/','4') == 'invalid'
 
) {return 'invalid';}
}
 
function validate_clientside_array($regex, $position)
{
$item = '/'.$position.'$/';
 //echo 'parameter 1 = <b>'.$regex.'</b><br />';
 //echo 'parameter 3 = <b>'.$position.'</b><br /><br />';
 
  foreach($_POST as $key => $value)
  if (preg_match($item, $key))
  {
   //if (preg_match($regex, $value)) {echo ' <b class="good">'.$key.' = '.$value.'</b> is a <b class="good">match</b>!</b><br />'."\n";}
   //else {echo '<b class="bad">'.$key.' == '.$value.'</b> not a <b class="bad">match</b>!</b><br />'; $validity = '1'; return 'not valid';}
   if (!preg_match($regex, $value)) {return 'invalid';}
   /*return false;*/
 }
}
 
$regex_0_selectors = '/([0-9A-z]([#|.|,|:][0-9A-z]){0,10})?$/';
$regex_1_colors    = '/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/';
$regex_2_bgimages  = '/^(([0-9]{2})\/([0-9]{3})|none)?$/';
 
echo '<b> R E S U L T = </b>'.super_validate();
echo '<br style="clear: both;" />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_0_selectors,'0').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_2_bgimages,'2').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'1').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'3').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'4').'<br />';
 
if (validate_clientside_array($regex_0_selectors,'0') != 'invalid'
&& validate_clientside_array($regex_1_colors,'1') != 'invalid'
&& validate_clientside_array($regex_2_bgimages,'2') != 'invalid'
&& validate_clientside_array($regex_1_colors,'3') != 'invalid'
&& validate_clientside_array($regex_1_colors,'4') != 'invalid'
) {echo '<br />The array contains <b class="good">only valid data</b>.';}
else {echo '<br />The array <b class="bad">contains invalid data</b>!';}
 
?>
</body>
</html>
So I passed the variables as parameters and reestablished the variables outside the function as variables within the super function.

On line 102 I define the parameters as the outside variables (the variables defined on lines 98~100).

Then inside of the parent function at line 55 I essentially redefined the variables.

It seems sort of a waste though?

So I'm open to suggestions: would it be better just to compare each function as I do on lines 110~114?

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>PHP Serverside Validation of CSS post data</title>
<style type="text/css">
body,html {font-family: monospace;}
b {color: #00f;}
b.bad {color: #f00;}
b.good {color: #0f0;}
div {outline: #f00 solid 1px;}
div.overflow {float: left; font-size: 12px; height: 240px; margin: 4px; overflow: auto; width: 25%;}
form {float: left; width: 400px;}
form input {font-size: 10px; width: 60px;}
</style>
</head>
<body>
 
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset>
<div>
<input name="ce000" value="body" />
<input name="ce001" value="444" />
<input name="ce002" value="11/002" />
<input name="ce003" value="00f" />
<input name="ce004" value="00f" />
</div>
<div>
<input name="ce010" value="h2, h2, h3, h4" />
<input name="ce011" value="transparent" />
<input name="ce012" value="none" />
<input name="ce013" value="1f1" />
<input name="ce014" value="115" />
</div>
<div>
<input name="ce020" value="div" />
<!-- Default Value below is invalid, add an extra digit (0-F Hex) to validate -->
<input name="ce021" style="background-color: #000; border-color: #f0f; color: #fff;" value="55555" />
<input name="ce022" value="01/002" />
<input name="ce023" value="5f6" />
<input name="ce024" value="5f6" />
</div>
<div>
<input name="ce030" value="span" />
<input name="ce031" value="7d6" />
<input name="ce032" value="" />
<input name="ce033" value="" />
<input name="ce034" value="" />
</div>
<br style="clear: both;" />
<input style="display: block; width: 60%;" type="submit" value="Validate Form Data" />
</fieldset>
</form>
 
<?php
function super_validate($regex_0_selectors, $regex_1_colors, $regex_2_bgimages)
{
$regex_0_selectors = $regex_0_selectors;
$regex_1_colors    = $regex_1_colors;
$regex_2_bgimages  = $regex_2_bgimages;
 
 
if (validate_clientside_array($regex_0_selectors,'0') != 'invalid'
&& validate_clientside_array($regex_1_colors,'1') != 'invalid'
&& validate_clientside_array($regex_2_bgimages,'2') != 'invalid'
&& validate_clientside_array($regex_1_colors,'3') != 'invalid'
&& validate_clientside_array($regex_1_colors,'4') != 'invalid'
 
/*
if (validate_clientside_array('/([0-9A-z]([#|.|,|:][0-9A-z]){0,10})?$/','0') == 'invalid'
||
validate_clientside_array('/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/','1') == 'invalid'
||
validate_clientside_array('/^(([0-9]{2})\/([0-9]{3})|none)?$/','2') == 'invalid'
||
validate_clientside_array('/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/','3') == 'invalid'
||
validate_clientside_array('/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/','4') == 'invalid'
*/
) {return 'invalid';}
}
 
function validate_clientside_array($regex, $position)
{
$item = '/'.$position.'$/';
 //echo 'parameter 1 = <b>'.$regex.'</b><br />';
 //echo 'parameter 3 = <b>'.$position.'</b><br /><br />';
 
  foreach($_POST as $key => $value)
  if (preg_match($item, $key))
  {
   //if (preg_match($regex, $value)) {echo ' <b class="good">'.$key.' = '.$value.'</b> is a <b class="good">match</b>!</b><br />'."\n";}
   //else {echo '<b class="bad">'.$key.' == '.$value.'</b> not a <b class="bad">match</b>!</b><br />'; $validity = '1'; return 'not valid';}
   if (!preg_match($regex, $value)) {return 'invalid';}
   /*return false;*/
 }
}
 
$regex_0_selectors = '/([0-9A-z]([#|.|,|:][0-9A-z]){0,10})?$/';
$regex_1_colors    = '/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/';
$regex_2_bgimages  = '/^(([0-9]{2})\/([0-9]{3})|none)?$/';
 
echo '<b> R E S U L T = </b>'.super_validate($regex_0_selectors, $regex_1_colors, $regex_2_bgimages);
echo '<br style="clear: both;" />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_0_selectors,'0').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_2_bgimages,'2').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'1').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'3').'<br />';
echo '<b> RESULT = </b> '.validate_clientside_array($regex_1_colors,'4').'<br />';
 
if (validate_clientside_array($regex_0_selectors,'0') != 'invalid'
&& validate_clientside_array($regex_1_colors,'1') != 'invalid'
&& validate_clientside_array($regex_2_bgimages,'2') != 'invalid'
&& validate_clientside_array($regex_1_colors,'3') != 'invalid'
&& validate_clientside_array($regex_1_colors,'4') != 'invalid'
) {echo '<br />The array contains <b class="good">only valid data</b>.';}
else {echo '<br />The array <b class="bad">contains invalid data</b>!';}
 
?>
</body>
</html>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Functions within functions not sending parameters?

Post by JAB Creations »

Functions (called) within functions...

Code: Select all

function something1()
{
something2();
something3();
something4();
}
You're correct, it's something basic though it's some sort of reverse scope with variables. I knew variables inside of the functions couldn't be referenced (local scope right?) though I was not aware that I could not reference variables outside of a function from within a function.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Functions within functions not sending parameters?

Post by Christopher »

I think you are doing too much. Also mixing application code with template code leads to confusion even for experienced programmers. Can you first post just your HTML form that you want get data from. Strip out everything else. That would be the best place to start.
(#10850)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Functions within functions not sending parameters?

Post by JAB Creations »

Everything necessary is already part of the code including an already existing form with almost all valid data (with the exception of the highlighted text input. Hence it's a copy and paste direct to test copy of code. Just copy it to a new text file and navigate to it on your local server. I intended it to be as easy to test as possible unless you're using a different environment where you can only test PHP code?

Any way this fully functional file was intended to help me visualize the output of the functions/regex filters, nothing more. There is no template code, the XHTML/CSS is merely for this standalone test file. I merely wanted to see if I could centralize it to a simple and only single condition though now I don't really feel it's worth the effort to consolidate five functions to one if I have to pass existing variables to the function unless I literally just move the variables around.

The important thing to understand from my perspective is that I personally need to visualize is the code is doing what I want it to do. Since it's a complex setup it's much easier for me to create a stand-alone file that I can work on. Only when it works as desired will I actually go to the point of integrating it as a module in my work.

If I strip all the clientside code it makes it more difficult to visualize results (since I'm dealing with arrays of data). If I can't make the script work as a stand alone file I sure as heck won't bother to integrate a broken script in to a larger project.

So the follow merely is intended to help me test various strings (both valid and invalid) to test against the effectiveness of my regex filters, nothing more. Here is that code...

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>PHP Serverside Validation of CSS post data</title>
<style type="text/css">
body,html {font-family: monospace;}
b {color: #00f;}
b.bad {color: #f00;}
b.good {color: #0f0;}
div {outline: #f00 solid 1px;}
div.overflow {float: left; font-size: 12px; height: 240px; margin: 4px; overflow: auto; width: 25%;}
form {float: left; width: 400px;}
form input {font-size: 10px; width: 60px;}
</style>
</head>
<body>
 
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset>
<div>
<input name="ce000" value="body" />
<input name="ce001" value="444" />
<input name="ce002" value="11/002" />
<input name="ce003" value="00f" />
<input name="ce004" value="00f" />
</div>
<div>
<input name="ce010" value="h2, h2, h3, h4" />
<input name="ce011" value="transparent" />
<input name="ce012" value="none" />
<input name="ce013" value="1f1" />
<input name="ce014" value="115" />
</div>
<div>
<input name="ce020" value="div" />
<input name="ce021" value="55555" />
<input name="ce022" value="01/002" />
<input name="ce023" value="5f6" />
<input name="ce024" value="5f6" />
</div>
<div>
<input name="ce030" value="span" />
<input name="ce031" value="7d6" />
<input name="ce032" value="" />
<input name="ce033" value="" />
<input name="ce034" value="" />
</div>
<div>
<input name="ce040" value="" />
<input name="ce041" value="" />
<input name="ce042" value="" />
<input name="ce043" value="" />
<input name="ce044" value="" />
</div>
<div>
<input name="ce050" value="" />
<input name="ce051" value="" />
<input name="ce052" value="" />
<input name="ce053" value="" />
<input name="ce054" value="" />
</div>
<div>
<input name="ce060" value="" />
<input name="ce061" value="" />
<input name="ce062" value="" />
<input name="ce063" value="" />
<input name="ce064" value="" />
</div>
<div>
<input name="ce070" value="" />
<input name="ce071" value="" />
<input name="ce072" value="" />
<input name="ce073" value="" />
<input name="ce074" value="" />
</div>
<div>
<input name="ce080" value="" />
<input name="ce081" value="" />
<input name="ce082" value="" />
<input name="ce083" value="" />
<input name="ce084" value="" />
</div>
<br style="clear: both;" />
<input style="display: block; width: 60%;" type="submit" value="Validate Form Data" />
</fieldset>
</form>
 
<?php
 
function validate_clientside_array($regex, $position)
{
$item = '/'.$position.'$/';
 echo 'parameter 1 = <b>'.$regex.'</b><br />';
 echo 'parameter 3 = <b>'.$position.'</b><br /><br />';
 
  foreach($_POST as $key => $value)
  if (preg_match($item, $key))
  {
   if (preg_match($regex, $value)) {echo ' <b class="good">'.$key.' = '.$value.'</b> is a <b class="good">match</b>!</b><br />'."\n";}
   else {echo '<b class="bad">'.$key.' == '.$value.'</b> not a <b class="bad">match</b>!</b><br />'; $validity = '1'; return 'not valid';}
   if (!preg_match($regex, $value)) {return 'invalid';}
   /*return false;*/
 }
}
 
 
 
$regex_0_selectors = '/([0-9A-z]([#|.|,|:][0-9A-z]){0,10})?$/';
$regex_1_colors    = '/^(?:(?:[0-9a-f]{3}){1,2}|transparent)?$/';
$regex_2_bgimages  = '/^(([0-9]{2})\/([0-9]{3})|none)?$/';
 
 
 
echo '<div class="overflow"><h3>Column 0 - Selectors</h3>';
validate_clientside_array($regex_0_selectors,'0');
echo '</div>';
 
echo '<div class="overflow"><h3>Column 2 - Background-images</h3>';
validate_clientside_array($regex_2_bgimages,'2');
echo '</div><br style="clear: both;" />';
 
echo '<div class="overflow"><h3>Column 1 - Hex Colors</h3>';
validate_clientside_array($regex_1_colors,'1');
echo '</div>';
 
echo '<div class="overflow"><h3>Column 3 - Hex Colors</h3>';
validate_clientside_array($regex_1_colors,'3');
echo '</div>';
 
echo '<div class="overflow"><h3>Column 4 - Hex Colors</h3>';
validate_clientside_array($regex_1_colors,'4');
 
echo '</div><br style="clear: both;" />';
?>
</body>
</html>
Any way in the grander scale of things I now can use the code for it's part in the sequence it was originally constructed for: validating POSTed CSS data before it goes on to the next step in the process.
Post Reply