OpenSencillo  2015.009
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
input.rewrite.inrew.php
1 <?php
10 {
18  protected function rewriteData($source,$illegal,$change)
19  {
20  $arr = str_ireplace($illegal,$change,$source);
21 
22  return $arr;
23  }
24 
30  public function dotVar($source)
31  {
32  return floatval(self::parseFloat($ptString));
33  }
34 
40  protected function parseFloat($ptString)
41  {
42  if (strlen($ptString) == 0) {
43  return false;
44  }
45 
46  $pString = str_replace(" ", "", $ptString);
47 
48  if (substr_count($pString, ",") > 1)
49  $pString = str_replace(",", "", $pString);
50 
51  if (substr_count($pString, ".") > 1)
52  $pString = str_replace(".", "", $pString);
53 
54  $pregResult = array();
55 
56  $commaset = strpos($pString,',');
57  if ($commaset === false) {$commaset = -1;}
58 
59  $pointset = strpos($pString,'.');
60  if ($pointset === false) {$pointset = -1;}
61 
62  $pregResultA = array();
63  $pregResultB = array();
64 
65  if ($pointset < $commaset) {
66  preg_match('#(([-]?[0-9]+(\.[0-9])?)+(,[0-9]+)?)#', $pString, $pregResultA);
67  }
68  preg_match('#(([-]?[0-9]+(,[0-9])?)+(\.[0-9]+)?)#', $pString, $pregResultB);
69  if ((isset($pregResultA[0]) && (!isset($pregResultB[0])
70  || strstr($preResultA[0],$pregResultB[0]) == 0
71  || !$pointset))) {
72  $numberString = $pregResultA[0];
73  $numberString = str_replace('.','',$numberString);
74  $numberString = str_replace(',','.',$numberString);
75  }
76  elseif (isset($pregResultB[0]) && (!isset($pregResultA[0])
77  || strstr($pregResultB[0],$preResultA[0]) == 0
78  || !$commaset)) {
79  $numberString = $pregResultB[0];
80  $numberString = str_replace(',','',$numberString);
81  }
82  else {
83  return false;
84  }
85  $result = (float)$numberString;
86  return $result;
87  }
88 }
89 ?>