Valid Parentheses CODE
// Determine whether parentheses are valid if they contain some kind of mathematical operations or just text
function isValid($string) {
    $len = strlen($string);
    $filtered = '';
    for ($x = 0;  $x < $len;  $x++) {
	$ASCII = ord($string[$x]);
	if (($ASCII==91 || $ASCII==93 || $ASCII==123 || $ASCII==125 || $ASCII==40 || $ASCII==41)) {
		$filtered .= $string[$x];
	}
    }
    $len2 = strlen($filtered);
    if($len2%2==1){
    return false;
    }
    $parentheses = [
	"("=>")", 
	"["=>"]" , 
	"{"=>"}",
    ];
    $open = [];
    for ($x = 0;  $x < $len2;  $x++) {
	if (array_key_exists($filtered[$x], $parentheses)) {
		array_push($open, $filtered[$x]);
	} else {
		$parenthesis = array_pop($open);
		if ($filtered[$x] != $parentheses[$parenthesis]) {
			return false;
		}
	}
    }
    if ($open) {
	return false;
    }
    return true;
}
echo isValid("{ :'> baeknwaw adanww a} [ daw  ] awda( :.a,a)a"); // returns true
echo isValid("(1 + 1) = 2"); // returns true
echo isValid("(1 + 1)) = 2"); // returns false
// enjoy with coding))
by Luka Khitaridze
2 years ago
PHP
Syntax
0
Pro tip: use ```triple backticks around text``` to write in code fences