I have wrote an regular expression that removed all the content from once bracket to end of bracket, But its not working, I wrote a explode code but its not working properly, anyone have an regular expression from that i can remove brackets and content inside them
Here is my code for explode:
$arr = explode(". ", $des);
$arr2= explode("(", $arr[0]);
$arr3=explode(")", $arr2[1]);
$arr[0]=$arr2[0].$arr3[1];
Please anyone provide me regular express from that
e.g: I am a web developer ($123.Abc) and I am from US.
I need to remove ($123.Abc) from the above line..
Please help!!!
I think something like this should do the job, if I understand well what you intend to do:
$target = preg_replace('~\([^)]*\)~', '', $des);
It finds all occurrences of ( followed by any number of any character which is not ) followed by ) and replaces them by an empty string.
If you want to use regex you can use the regex in the castis comment:
<?php
$string = 'I am a web developer ($123.Abc) and I am from US.';
$new_string = preg_replace('/\(.+\) /', '', $string);
echo $new_string . PHP_EOL;
?>
An if you want to use explode, should be something like this:
$string = 'I am a web developer ($123.Abc) and I am from US.';
$array = explode('(', $string);
$array1 = explode(')', $string);
$new_string = $array[0] . $array1[1];
echo $new_string . PHP_EOL;