Hello all,
I'm trying to read an array and my purpose is whenever I see a value which is all ***** (between 30-100) I want to do store this value.
here is what I got:
function isStar($string)
{
if(preg_match("/^\*{30,100}\*$/",$string))
return true;
else
return false;
}
for ($i=0;$i<count($allArr);$i++)
{
$aLine=$allArr[$i];
if(isStar($aLine))
{
if(isStar( $allArr[$i+1]) || isStar($allArr[$i+2])) || isStar($allArr[$i+3])) )
/*do something*/
}
}
it keeps getting false answeres and never true though it should!
any ideas?
thanks
what is wrong with that?
Moderator: General Moderators
you seem to have some basic structure errors in your code, i have ironed out what i can see
Mark
Code: Select all
function isStar($string) {
if(preg_match("/^\*{30,100}\*$/",$string)) {
return true;
} else {
return false;
}
}
for ($i=0;$i<count($allArr);$i++) {
$aLine=$allArr[$i];
if(isStar($aLine)) {
if(isStar( $allArr[$i+1]) || isStar($allArr[$i+2])) || isStar($allArr[$i+3])) ) {
/*do something*/
}
}
}try replacing your function with this
Mark
Code: Select all
function isStar($string) {
if (substr_count($string, "*") >= 30 && substr_count($string, "*") <= 100) {
return true;
} else {
return false;
}
}