XML : Parse mahml to desired form in php not working

I have a an equation as 3 x squared as follows:

enter image description here

This Image I am getting from Wiris editor and I am posting this to another page on action button. The action page will look as follows:

  <?php    echo $text =  $_POST['title']['text'];  ?>    

When I echoed I am getting like this:

  «math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mn»3«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«/math»    

Which is obviously Mathml :

I tried to parse it as follow to get desired form:

  <?php    echo $text =  $_POST['title']['text'];    $xmlstring = $_POST['title']['text'];    $xml = simplexml_load_string($xmlstring);  var_dump($xml);  echo $xml->math, PHP_EOL;    ?>    

But it is not getting correctly.

What I need ios as follows: If My Mathml expression is 3 x squared then I need result as 3*x^2 . If 3x then it should be parsed as 3*x.

Please guide me.

No comments:

Post a Comment