I'm looking to split the following strings based upon the operator between them. If there is parenthesis then we have to keep the entire parenthesis together.
Here's the types of strings I will have.
(1.25*1.5)-(10.5/2.15625)
(1.25*1.5)+10.75
1.25*(10.5/10.75)
1.25/10.5
The desired output I'm looking for is this
array(){
[0]=>
string = "(1.25*1.5)"
[1]=>
string = "-"
[2]=>
string = "(10.5/2.15625)"
}
array(){
[0]=>
string = "(1.25*1.5)"
[1]=>
string = "+"
[2]=>
string = "10.75"
}
array(){
[0]=>
string = "1.25"
[1]=>
string = "*"
[2]=>
string = "(10.5/10.75)"
}
array(){
[0]=>
string = "1.25"
[1]=>
string = "/"
[2]=>
string = "10.5"
}
this is what I have so far.
$expression_parts = preg_split('~([<>=]+)~', $expression, NULL,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ) ;