I want to remove everything inside braces. For example, if string is:
[hi] helloz [hello] (hi) {jhihi}
then, I want the output to be only helloz
.
I am using the following code, however it seems to me that there should be a better way of doing it, is there?
$name = "[hi] helloz [hello] (hi) {jhihi}";
$new = preg_replace("/\([^)]+\)/","",$name);
$new = preg_replace('/\[.*\]/', '', $new);
$new = preg_replace('/\{.*\}/', '', $new);
echo $new;
This should work:
$name = "[hi] helloz [hello] (hi) {jhihi}";
echo preg_replace('/[\[{\(].*?[\]}\)]/' , '', $name);
Paste it somewhere like: http://writecodeonline.com/php/ to see it work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With