fork(2) download
  1. <?php
  2.  
  3. $re = '/(?J)(?<num>[0-9]*[.,]?[0-9]+)\h*(?<cur>\p{Sc})|(?<cur>\p{Sc})\h*(?<num>[0-9]*[.,]?[0-9]+)/u';
  4. $str = '12€
  5. 12 €
  6. €12
  7. € 12
  8. 12$
  9. 12 $
  10. $12
  11. $ 12';
  12. echo preg_replace_callback($re, function($m) {
  13. return $m["num"] . " " . $m["cur"];
  14. }, $str);
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout
12 €
12 €
12 €
12 €
12 $
12 $
12 $
12 $