note 31640 deleted from function.array-pop by didou
| From: | didou@php.net | Date: | Sun, 18 May 2003 02:22:31 +0000 |
| Subject: | note 31640 deleted from function.array-pop by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48331@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 - http://www.torsoft.tk
function validate ($string){
$Stack=array("");
array_pop($Stack);
$i=0;
while ($i<=strlen($string)){
$ft=substr($string,$i,1);
if ($ft=="(")
array_push($Stack,$ft);
elseif ($ft==")")
array_pop($Stack);
$i++;
}
return sizeof($Stack)==0;
}