Formatization of chemical reactions on php



  • There are textual chemical reactions from the base, like:

    Ce2(SO4)3 + (NH4)2S2O8 = 2Ce(SO4)2 + (NH4)2SO4

    All numbers (including overlaps) need to be built (addition of html strategies) <sub>except for the numbers at the beginning of the line and after the gaps.

    I tried to make a sedative, but it's kind of hard. I've been told that it's sort of a way to simplify or use a mass or regular expressions.preg_match) I found regular expressions how to make all the numbers straight, but I can't limit the sample.

    How can we handle this line properly and rationally?



  • Thank you, splash58! In the end, the line was:

    $formula = preg_replace("/(?<=[A-Za-z)\]])\d+(,\d+)*/","<sub>$0</sub>", $formula)
    

    which makes line html with numbers in the form of substrate indices. The second option you proposed does not take two-digit numbers.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2