From f6025fa55700b762a61e615210ccf7f4307d7459 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 18 Jan 2019 22:28:03 +0100 Subject: [PATCH] Str_replace replaces every occurence --- src/Sws.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Sws.php b/src/Sws.php index 60d040e..6f67157 100644 --- a/src/Sws.php +++ b/src/Sws.php @@ -290,17 +290,24 @@ class Sws private static function ReadHexData(String $data) { $hex = implode(unpack("H*", $data)); - $hex = implode(array_reverse(str_split($hex, 2))); - $hex = str_replace("00", "", $hex); + $hex = array_reverse(str_split($hex, 2)); + + foreach ($hex as $key=>$item) { + if ($item == "00") { + $hex[$key] = ""; + } else { + break; + } + } + + $hex = implode($hex); return $hex; } private static function UIntToTimestamp($date) { - //echo $date; $curyear = date('Y'); $yearoffset = $curyear - self::PT_PASTOFFSET; - //$yearoffset = 100; // Day $day = $date % self::PT_DAYFACTOR; @@ -320,7 +327,6 @@ class Sws $concat = $month . '/' . $day . '/' . intval($year); $format = 'm/d/Y'; - echo $concat; return \DateTime::createFromFormat($format, $concat); }