note 31212 deleted from function.array-push by didou
| From: | didou@php.net | Date: | Sun, 18 May 2003 02:25:56 +0000 |
| Subject: | note 31212 deleted from function.array-push by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48333@lists.php.net to get a copy of this message | ||
Note Submitter: t0rus@dr.com
----
//here's an example of how to check if the string has properly
//closed brakets for ex. if it has (())(()(())) or ))(())((()))))))
//using stack, returns true if the string is ok,
//and false otherwise
//it pushes "(" into stack if it finds it and pops it out if finds ")" after it
//i'm not used to programming in php so, don't mind the
//mistakes, if u've got any suggestions or questions go to my site - h**p://www.torsoft.tk
function validate ($string){
$Stack=array("");
$i=-1;
while ($i++<strlen($string)){ //checking the entire string
$ft=substr($string,$i,1);
if ($ft=="(") array_push($Stack,$ft);
elseif ($ft==")") array_pop($Stack);
}
return sizeof($Stack)==0;
}