Skip to content
Advertisement

PHP check if string contains brackets

I just want to build a php function that checking if string is contain brackets and return boolean, anyone can help?

example:

$string = "{hallo}"; // true
$string2 = "h{allo}"; //true
$string3 = "hal}{o"; //false
$string4 = "hallo{}";//false

Advertisement

Answer

Check this

<?php

$string = "{hallo}"; 

$res = preg_match('/{w+}/',$string);

print_r($res);

?>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement