Oara\Utilities::parseDouble PHP Метод

parseDouble() публичный статический Метод

Parse Double, delete odd characters.
public static parseDouble ( $data ) : double
$data
Результат double
    public static function parseDouble($data)
    {
        $data = \preg_replace('/[^0-9\\.,\\-]/', "", $data);
        $data = \str_replace(" ", "", \trim($data));
        $double = 0;
        if ($data != null) {
            $bits = \explode(",", \trim($data));
            // split input value up to allow checking
            $last = \strlen($bits[\count($bits) - 1]);
            // gets part after first comma (thousands (or decimals if incorrectly used by user)
            if ($last < 3) {
                // checks for comma being used as decimal place
                $convertnum = \str_replace(",", ".", \trim($data));
            } else {
                $convertnum = \str_replace(",", "", \trim($data));
            }
            $double = \number_format((double) $convertnum, 2, '.', '');
        }
        return $double;
    }

Usage Example

Пример #1
0
 /**
  * @return array
  * @throws \Exception
  */
 public function getPaymentHistory()
 {
     $paymentHistory = array();
     $urls = array();
     $urls[] = new \Oara\Curl\Request('http://affiliates.affiliatefuture.com/myaccount/invoices.aspx', array());
     $exportReport = $this->_client->get($urls);
     $doc = new \DOMDocument();
     @$doc->loadHTML($exportReport[0]);
     $xpath = new \DOMXPath($doc);
     $tableList = $xpath->query('//table');
     $registerTable = $tableList->item(12);
     if ($registerTable == null) {
         throw new \Exception('Fail getting the payment History');
     }
     $registerLines = $registerTable->childNodes;
     for ($i = 1; $i < $registerLines->length; $i++) {
         $registerLine = $registerLines->item($i)->childNodes;
         $obj = array();
         $date = \DateTime::createFromFormat("d/m/Y", trim($registerLine->item(1)->nodeValue));
         $date->setTime(0, 0);
         $obj['date'] = $date->format("Y-m-d H:i:s");
         $obj['pid'] = trim($registerLine->item(0)->nodeValue);
         $value = trim(substr(trim($registerLine->item(4)->nodeValue), 4));
         $obj['value'] = \Oara\Utilities::parseDouble($value);
         $obj['method'] = 'BACS';
         $paymentHistory[] = $obj;
     }
     return $paymentHistory;
 }
All Usage Examples Of Oara\Utilities::parseDouble