original_string: public static function toPHPDateFormat($excelDateFormat)
      {
          // Remove brackets potentially present at the beginning of the format string
          // and text portion of the format at the end of it (starting with ";")
          // See §18.8.31 of ECMA-376 for more detail.
          $dateFormat = preg_replace('/^(?:\[\$[^\]]+?\])?([^;]*).*/', '$1', $excelDateFormat);
  
          // Double quotes are used to escape characters that must not be interpreted.
          // For instance, ["Day " dd] should result in "Day 13" and we should not try to interpret "D", "a", "y"
          // By exploding the format string using double quote as a delimiter, we can get all parts
          // that must be transformed (even indexes) and all parts that must not be (odd indexes).
          $dateFormatParts = explode('"', $dateFormat);
  
          foreach ($dateFormatParts as $partIndex => $dateFormatPart) {
              // do not look at odd indexes
              if ($partIndex % 2 === 1) {
                  continue;
              }
  
              // Make sure all characters are lowercase, as the mapping table is using lowercase characters
              $transformedPart = strtolower($dateFormatPart);
  
              // Remove escapes related to non-format characters
              $transformedPart = str_replace('\\', '', $transformedPart);
  
              // Apply general transformation first...
              $transformedPart = strtr($transformedPart, self::$excelDateFormatToPHPDateFormatMapping[self::KEY_GENERAL]);
  
              // ... then apply hour transformation, for 12-hour or 24-hour format
              if (self::has12HourFormatMarker($dateFormatPart)) {
                  $transformedPart = strtr($transformedPart, self::$excelDateFormatToPHPDateFormatMapping[self::KEY_HOUR_12]);
              } else {
                  $transformedPart = strtr($transformedPart, self::$excelDateFormatToPHPDateFormatMapping[self::KEY_HOUR_24]);
              }
  
              // overwrite the parts array with the new transformed part
              $dateFormatParts[$partIndex] = $transformedPart;
          }
  
          // Merge all transformed parts back together
          $phpDateFormat = implode('"', $dateFormatParts);
  
          // Finally, to have the date format compatible with the DateTime::format() function, we need to escape
          // all characters that are inside double quotes (and double quotes must be removed).
          // For instance, ["Day " dd] should become [\D\a\y\ dd]
          $phpDateFormat = preg_replace_callback('/"(.+?)"/', function($matches) {
              $stringToEscape = $matches[1];
              $letters = preg_split('//u', $stringToEscape, -1, PREG_SPLIT_NO_EMPTY);
              return '\\' . implode('\\', $letters);
          }, $phpDateFormat);
  
          return $phpDateFormat;
      }
code: public static function toPHPDateFormat($excelDateFormat)
      {
          // Remove brackets potentially present at the beginning of the format string
          // and text portion of the format at the end of it (starting with ";")
          // See §18.8.31 of ECMA-376 for more detail.
          $dateFormat = preg_replace('/^(?:\[\$[^\]]+?\])?([^;]*).*/', '$1', $excelDateFormat);
  
          // Double quotes are used to escape characters that must not be interpreted.
          // For instance, ["Day " dd] should result in "Day 13" and we should not try to interpret "D", "a", "y"
          // By exploding the format string using double quote as a delimiter, we can get all parts
          // that must be transformed (even indexes) and all parts that must not be (odd indexes).
          $dateFormatParts = explode('"', $dateFormat);
  
          foreach ($dateFormatParts as $partIndex => $dateFormatPart) {
              // do not look at odd indexes
              if ($partIndex % 2 === 1) {
                  continue;
              }
  
              // Make sure all characters are lowercase, as the mapping table is using lowercase characters
              $transformedPart = strtolower($dateFormatPart);
  
              // Remove escapes related to non-format characters
              $transformedPart = str_replace('\\', '', $transformedPart);
  
              // Apply general transformation first...
              $transformedPart = strtr($transformedPart, self::$excelDateFormatToPHPDateFormatMapping[self::KEY_GENERAL]);
  
              // ... then apply hour transformation, for 12-hour or 24-hour format
              if (self::has12HourFormatMarker($dateFormatPart)) {
                  $transformedPart = strtr($transformedPart, self::$excelDateFormatToPHPDateFormatMapping[self::KEY_HOUR_12]);
              } else {
                  $transformedPart = strtr($transformedPart, self::$excelDateFormatToPHPDateFormatMapping[self::KEY_HOUR_24]);
              }
  
              // overwrite the parts array with the new transformed part
              $dateFormatParts[$partIndex] = $transformedPart;
          }
  
          // Merge all transformed parts back together
          $phpDateFormat = implode('"', $dateFormatParts);
  
          // Finally, to have the date format compatible with the DateTime::format() function, we need to escape
          // all characters that are inside double quotes (and double quotes must be removed).
          // For instance, ["Day " dd] should become [\D\a\y\ dd]
          $phpDateFormat = preg_replace_callback('/"(.+?)"/', function($matches) {
              $stringToEscape = $matches[1];
              $letters = preg_split('//u', $stringToEscape, -1, PREG_SPLIT_NO_EMPTY);
              return '\\' . implode('\\', $letters);
          }, $phpDateFormat);
  
          return $phpDateFormat;
      }
code_tokens: public static function toPHPDateFormat ( $ excelDateFormat ) { // Remove brackets potentially present at the beginning of the format string // and text portion of the format at the end of it (starting with ";") // See §18.8.31 of ECMA-376 for more detail. $ dateFormat = preg_replace ( '/^(?:\[\$[^\]]+?\])?([^;]*).*/' , '$1' , $ excelDateFormat ) ; // Double quotes are used to escape characters that must not be interpreted. // For instance, ["Day " dd] should result in "Day 13" and we should not try to interpret "D", "a", "y" // By exploding the format string using double quote as a delimiter, we can get all parts // that must be transformed (even indexes) and all parts that must not be (odd indexes). $ dateFormatParts = explode ( '"' , $ dateFormat ) ; foreach ( $ dateFormatParts as $ partIndex => $ dateFormatPart ) { // do not look at odd indexes if ( $ partIndex % 2 === 1 ) { continue ; } // Make sure all characters are lowercase, as the mapping table is using lowercase characters $ transformedPart = strtolower ( $ dateFormatPart ) ; // Remove escapes related to non-format characters $ transformedPart = str_replace ( '\\' , '' , $ transformedPart ) ; // Apply general transformation first... $ transformedPart = strtr ( $ transformedPart , self :: $ excelDateFormatToPHPDateFormatMapping [ self :: KEY_GENERAL ] ) ; // ... then apply hour transformation, for 12-hour or 24-hour format if ( self :: has12HourFormatMarker ( $ dateFormatPart ) ) { $ transformedPart = strtr ( $ transformedPart , self :: $ excelDateFormatToPHPDateFormatMapping [ self :: KEY_HOUR_12 ] ) ; } else { $ transformedPart = strtr ( $ transformedPart , self :: $ excelDateFormatToPHPDateFormatMapping [ self :: KEY_HOUR_24 ] ) ; } // overwrite the parts array with the new transformed part $ dateFormatParts [ $ partIndex ] = $ transformedPart ; } // Merge all transformed parts back together $ phpDateFormat = implode ( '"' , $ dateFormatParts ) ; // Finally, to have the date format compatible with the DateTime::format() function, we need to escape // all characters that are inside double quotes (and double quotes must be removed). // For instance, ["Day " dd] should become [\D\a\y\ dd] $ phpDateFormat = preg_replace_callback ( '/"(.+?)"/' , function ( $ matches ) { $ stringToEscape = $ matches [ 1 ] ; $ letters = preg_split ( '//u' , $ stringToEscape , - 1 , PREG_SPLIT_NO_EMPTY ) ; return '\\' . implode ( '\\' , $ letters ) ; } , $ phpDateFormat ) ; return $ phpDateFormat ; }
docstring: Converts the given Excel date format to a format understandable by the PHP date function.
  
  @param string $excelDateFormat Excel date format
  @return string PHP date format (as defined here: http://php.net/manual/en/function.date.php)
docstring_tokens: Converts the given Excel date format to a format understandable by the PHP date function .