Issue
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;
Solution
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.
Answered By - Damien Overeem Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.