With the help of ir4z04, I was able to get my little script working. I appreciate all the help, but now I have another question.
If I want to make the second for loop/if statement case insensitive, how can I do that?
<?php
$states[0] = $POST["states0"];
$states[1] = $POST["states1"];
$states[2] = $POST["states2"];
$states[3] = $POST["states3"];
$states[4] = $POST["states4"];
$states[5] = $POST["states5"];
$states[6] = $POST["states6"];
$states[7] = $POST["states7"];
$cond1 = "xas";
for ($x=0; $x < sizeof($states); $x++)
{
if(substr($states[$x],strlen($states[$x]) - strlen($cond1)) == $cond1)
{
$states[0] = $states[$x];
echo "Match Found in \$states[" . $x . "] for xas<br>";
}
else
{
echo "No Match in \$states[" . $x . "] for xas<br>";
}
}
$cond2 = "k";
$cond3 = "s";
for ($x=0; $x < sizeof($states); $x++)
{
if (preg_match("/${cond2}.${cond3}$/",$states[$x]))
{
$states[1] = $states[$x];
echo "Match Found in \$states[" . $x . "] for ks<br>";
}
else
{
echo "No Match in \$states[" . $x . "] for k*s<br>";
}
}
$cond4 = "M";
for ($x=0; $x < sizeof($states); $x++)
{
if(substr($states[$x],0,1) == $cond4)
{
$states[2] = $states[$x];
echo "Match Found in \$states[" . $x . "] for M<br>";
}
else
{
echo "No Match in \$states[" . $x . "] for M<br>";
}
}
echo $states[3] . "<br>";
echo $states[4] . "<br>";
echo $states[5] . "<br>";
echo $states[6] . "<br>";
echo $states[7] . "<br>";
echo $states[0] . "<br>";
echo $states[1] . "<br>";
echo $states[2] . "<br>";
?>
$cond2 = "k";
$cond3 = "s";
for ($x=0; $x < sizeof($states); $x++)
{
if (preg_match("/^${cond2}.*${cond3}$/",$states[$x]))
{
$states[1] = $states[$x];
echo "Match Found in \$states[" . $x . "] for k*s<br>";
}
else
{
echo "No Match in \$states[" . $x . "] for k*s<br>";
}
}
I tried using
if (preg_match("/${cond2}/i.*${cond3}/i$/",$states[$x]))
but that didn't work. I am almost positive I need to use /i but I can't figure out where. Thanks for anyone who can help me. The rest of my code works fine. (I did the last search myself, yay!)