Page 1 of 1

what is wrong with that?

Posted: Tue Sep 09, 2003 3:28 am
by yaron
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

Posted: Tue Sep 09, 2003 3:47 am
by yaron
well, I found what is the problem but I still don't know how to solve it.
whenever I read a value I use the trim function to remove pre and post whitesapces.
I need to use trim for other purpose but when I use it the isStar function returns false no matter what!

Posted: Tue Sep 09, 2003 3:50 am
by JayBird
you seem to have some basic structure errors in your code, i have ironed out what i can see

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*/ 
		} 
	} 
}
Mark

Posted: Tue Sep 09, 2003 3:59 am
by yaron
my problem is with mu isStar function.
is there a better way to determine oif a string contains between 30-100 stars and nothing else?

Posted: Tue Sep 09, 2003 4:10 am
by JayBird
try replacing your function with this

Code: Select all

function isStar($string) { 
   
   if (substr_count($string, "*") >= 30 && substr_count($string, "*") <= 100) {
      return true; 
   } else { 
      return false; 
   } 
}
Mark