Forum Moderators: coopster
Example:
$var1 = "test1;";
$var2 = "test2";
$var3 = "test3";
$var4 = "test4";
$variables = array ($var1,$var2,$var3,$var4);
for ($i = 0; $i < 4; $i++) {
if (!eregi('1', $variables[$i])) die("ACCESS DENIED.");
}
echo "okay";
I would like a regular expression to test for no match rather than a match. Here I'm using a for loop to cycle through some variables and test for no match for the literal '1'. Yet this script keeps outputting 'ACCESS DENIED' and I don't get it. The first variable contains a '1' in it, hence a match is found and the script should echo 'okay'.
The following script works as I expect it to. It's the exact same thing except it tests for no match for 'test'. Since a match is found, it prints 'okay'.
$var1 = "test1;";
$var2 = "test2";
$var3 = "test3";
$var4 = "test4";
$variables = array ($var1,$var2,$var3,$var4);
for ($i = 0; $i < 4; $i++) {
if (!eregi('test', $variables[$i])) die("ACCESS DENIED.");
}
echo "okay";
I suspect that this is due to some simple blunder I've made. I would greatly appreciate if someone would point it out.
Much thanks.
YES or NO?
Anybody?
In my original script, I replaced the literal '1' with the class '[0-9]' and now the script is performing as I expect it to. Not sure why the '1' malfunctions. According to my information, a literal can be any character (albeit certain characters have to be escaped using the '\'). As I said, still learning... :o)