Friends,
I have a silly doubt:
Assume that I have a line like this
Heading: Value1; SomeText1 (a, b, c), Value 2; SomeText2 (d, e, f)
I wanted to remove all semicolon and remove 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 Assume I have a line like this
Heading: Text1 (a, b) Text2. (d, f) Text3 (g, h)
What I want to achieve is... Remove everything with in brackets (inclusive brackets) and replace it with comma. However the last ocurance of the bracket should not be replace with a a comma.
I mean the output should be
Heading: Text1 , Text2. , Text3
How to achive this?