I have trouble to find the multiple string and replace it with the new string within an array.
this is my array
array (0) = <mfenced><mfrac><mrow><mn>2</mn><mi>x</mi><mo>+</mo><mn>3</mn></mrow><mi>x</mi></mfrac></mfenced>
array (1) = <mfenced><mrow><mn>2</mn><mi>x</mi><mo>+</mo><mn>3</mn></mrow></mfenced>
I need to find <mrow> and look for the next tag, if the next tag is <mo> then I no need to anything, else I need to add <mo>+</mo> next to it.
for example
array (0) = <mfenced><mfrac><mrow><mo>+</mo><mn>2</mn><mi>x</mi><mo>+</mo><mn>3</mn></mrow><mi>x</mi></mfrac></mfenced>
array (1) = <mfenced><mrow><mo>+</mo><mn>2</mn><mi>x</mi><mo>+</mo><mn>3</mn></mrow></mfenced>
this is my current code
$res1=array();
$temp = [];
for ($i=0; $i <count($addplus) ; $i++) {
$res1 = $addplus[$i];
while($pos = strpos($res1, "<mrow>",1))
{
if ($pos1=substr($res1,$pos,$pos + 4) != "<mo>")
{
$temp=str_replace($pos, "<mrow><mo>+</mo>", $res1);
}
else
{
$temp= $res1;
}
}
}
print_r($temp);
$addplus store the array. thank you in advance, have a nice day!