Friends,
I have silly doubts:
Suppose I have a line like this
Heading: Value1; SomeText1 (a, b, c), Value 2; SomeText2 (d, e, f)
I wanted to remove all semicolons and delete everything in brackets (including brackets). I managed to do this using this code
if (strstr($line,'Heading')){
$new_heading = str_replace(";", "", $line); // Replaces semi-colon
$new_heading = preg_replace("/\([^\)]+\)/","",$new_heading); //Removes Text With in Brackets
$line = $new_heading;
echo $line; //Outputs "Heading: Value1 SomeText1 , Value 2 SomeText2"
}
Now suppose I have a line like this
Heading: Text1 (a, b) Text2. (d, f) Text3 (g, h)
What I want to achieve is to remove everything in brackets (parentheses included) and replace it with a comma. However, the last bracket condition should not be replaced with a comma.
I mean, the conclusion should be
Heading: Text1 , Text2. , Text3
How to achieve this?
source
share