- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
<?php
function bracket_checker($input_string)
{
$checked = true;
$bracket1_open = "(";
$bracket1_close = ")";
$bracket2_open = "[";
$bracket2_close = "]";
$bracket3_open = "{";
$bracket3_close = "}";
If (strlen($input_string)> 30)
die("Wrong length of the input string!");
$bracket1_count= substr_count($input_string,$bracket1_open);
$bracket2_count= substr_count($input_string,$bracket1_close);
If ($bracket1_count != $bracket2_count)
$checked = false;
$bracket1_count= substr_count($input_string,$bracket2_open);
$bracket2_count= substr_count($input_string,$bracket3_close);
If ($bracket1_count != $bracket2_count)
$checked = false;
$bracket1_count= substr_count($input_string,$bracket3_open);
$bracket2_count= substr_count($input_string,$bracket3_close);
If ($bracket1_count != $bracket2_count)
$checked = false;
If ($checked)
print("Check passed!");
else
print("Check failed!");
}
echo "ab ( cd ()[]) ef{5} - "; bracket_checker("ab ( cd ()[]) ef{5}"); echo "\n";
echo "ab ( cd { ef ) gh } ij - "; bracket_checker("ab ( cd { ef ) gh } ij"); echo "\n";
?>