I have the following piece of code that I'm having trouble with.
The behavior is rather strange. Even if all three calls to ereg return true, only the first if statement executes. The other two are skipped. If the first call to ereg,
i.e. ereg("[[:alpha:]]",$titlestr) returns false and the second and third calls return true, only the second if statement is executed. If the first and second calls to ereg are false and the third call to ereg is true, then the third if statement executes.
However, if I write the if statement for the second and third calls to ereg as
if(!ereg("[[:alpha:]]",$keystr)), then when the first statement is true, both the second and third if statements execute, even if the call to the ereg function should be false in both cases.
The gist is this: only the first call to ereg that returns true causes the if statement to execute as it should (as I want it to anyway). After the first call to ereg returns true, the following if statements executes only when the if statement is set to a not condition ie if(!ereg("[[:alpha:]]",$keystr)). And further, the if statements only execute if the not statement is false!
In the following code the first ifstatement executes but not the second or third, even though the strings $keystr and $bothstr satisfy the condition.
if(ereg("[[:alpha:]]",$titlestr)){
$titles = getKeysFrom($titlestr);
}
if(ereg("[[:alpha:]]",$keystr)){
$keys = getKeysFrom($keystr);
}
if(ereg("[[:alpha:]]",$bothstr)){
$both = getKeysFrom($bothstr);
}
In the following code all three statements execute, even though $keystr and $bothstr don't satisfy the condition. (That is they contain a letter).
if(ereg("[[:alpha:]]",$titlestr)){
$titles = getKeysFrom($titlestr);
}
if(!ereg("[[:alpha:]]",$keystr)){
$keys = getKeysFrom($keystr);
}
if(!ereg("[[:alpha:]]",$bothstr)){
$both = getKeysFrom($bothstr);
}
I hope that this is not too long and that it's understandable.