Skip to content

Instantly share code, notes, and snippets.

@onbjerg
Last active August 29, 2015 14:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save onbjerg/5ff1201dd9348294c789 to your computer and use it in GitHub Desktop.
<?php
$water = 'H2O';
parseMolecule($water); // => ['H' => 2, 'O' => 1];
$magnesiumHydroxide = 'Mg(OH)2';
parseMolecule($magnesiumHydroxide); // => ['Mg' => 1, 'O' => 2, 'H' => 2];
$fremySalt = 'K4[ON(SO3)2]2';
parseMolecule($fremySalt); // => ['K' => 4, 'O' => 14, 'N' => 2, 'S' => 4];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment