Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Проверка строки на верное количество скобок на php
<?php
$string = 'This is (ok)';
function bracketValidation($string)
{
$counter = 0;
$openBracket = ['(','{','['];
$closedBracket = [')','}',']'];
$length = strlen($string);
for($i = 0; $i<$length; $i++)
{
$char = $string[$i];
if(in_array($char, $openBracket))
{
$counter ++;
}
elseif(in_array($char, $closedBracket))
{
$counter --;
}
}
if($counter != 0)
{
return false;
}
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.