Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. $date = "09/10/2019";
  3. $money = "1000,00";
  4. $date_array = explode("/",$date); // split the array
  5. $var_day = $date_array[0]; //day seqment
  6. $var_month = $date_array[1]; //month segment
  7. $var_year = $date_array[2]; //year segment
  8. $new_date_format = "$var_year-$var_day-$var_month"; // join them together
  9.  
  10. function convertDate($date) {
  11. // EN-Date to GE-Date
  12. if (strstr($date, "-") || strstr($date, "/")) {
  13. $date = preg_split("/[\/]|[-]+/", $date);
  14. $date = $date[2]."-".$date[1]."-".$date[0];
  15. return $date;
  16. }
  17.  
  18. return false;
  19. }
  20.  
  21. function getAmount($money){
  22. $cleanString = preg_replace('/([^0-9\.,])/i', '', $money);
  23. $onlyNumbersString = preg_replace('/([^0-9])/i', '', $money);
  24.  
  25. $separatorsCountToBeErased = strlen($cleanString) - strlen($onlyNumbersString) - 1;
  26.  
  27. $stringWithCommaOrDot = preg_replace('/([,\.])/', '', $cleanString, $separatorsCountToBeErased);
  28. $removedThousendSeparator = preg_replace('/(\.|,)(?=[0-9]{3,}$)/', '', $stringWithCommaOrDot);
  29.  
  30. return (float) str_replace(',', '.', $removedThousendSeparator);
  31. }
  32. echo $date;
  33. echo "<br>";
  34. echo convertDate($date);
  35. echo "<br>";
  36. echo $money;
  37. echo "<br>";
  38. echo getAmount($money);
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement