fork(1) download
  1. <?php
  2.  
  3. function formatar($preco) {
  4. return number_format(str_replace('.', '', $preco), 2, '.', '');
  5. }
  6.  
  7. $texto = 'Melhor preço sem escalas R$ 1.367\n-Melhor preço com escalas R$ 994';
  8. if (preg_match('/sem escalas R\$ (\d+(?:\.\d{3})*).*com escalas R\$ (\d+(?:\.\d{3})*)/s', $texto, $matches)) {
  9. var_dump($matches);
  10. echo "Sem escalas: ". formatar($matches[1]);
  11. echo "\nCom escalas: ". formatar($matches[2]);
  12. }
Success #stdin #stdout 0.02s 24656KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(55) "sem escalas R$ 1.367\n-Melhor preço com escalas R$ 994"
  [1]=>
  string(5) "1.367"
  [2]=>
  string(3) "994"
}
Sem escalas: 1367.00
Com escalas: 994.00