Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400]

(no description)

File Size: 173 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

EncodingHelper:: (8 methods):
  __construct()
  getBytesOffsetToSkipBOM()
  hasBOM()
  attemptConversionToUTF8()
  attemptConversionFromUTF8()
  attemptConversion()
  canUseIconv()
  canUseMbString()


Class: EncodingHelper  - X-Ref

Class EncodingHelper
This class provides helper functions to work with encodings.

__construct($globalFunctionsHelper)   X-Ref

param: \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper

getBytesOffsetToSkipBOM($filePointer, $encoding)   X-Ref
Returns the number of bytes to use as offset in order to skip the BOM.

return: int Bytes offset to apply to skip the BOM (0 means no BOM)
param: resource $filePointer Pointer to the file to check
param: string $encoding Encoding of the file to check

hasBOM($filePointer, $encoding)   X-Ref
Returns whether the file identified by the given pointer has a BOM.

return: bool TRUE if the file has a BOM, FALSE otherwise
param: resource $filePointer Pointer to the file to check
param: string $encoding Encoding of the file to check

attemptConversionToUTF8($string, $sourceEncoding)   X-Ref
Attempts to convert a non UTF-8 string into UTF-8.

return: string The converted, UTF-8 string
param: string $string Non UTF-8 string to be converted
param: string $sourceEncoding The encoding used to encode the source string

attemptConversionFromUTF8($string, $targetEncoding)   X-Ref
Attempts to convert a UTF-8 string into the given encoding.

return: string The converted string, encoded with the given encoding
param: string $string UTF-8 string to be converted
param: string $targetEncoding The encoding the string should be re-encoded into

attemptConversion($string, $sourceEncoding, $targetEncoding)   X-Ref
Attempts to convert the given string to the given encoding.
Depending on what is installed on the server, we will try to iconv or mbstring.

return: string The converted string, encoded with the given encoding
param: string $string string to be converted
param: string $sourceEncoding The encoding used to encode the source string
param: string $targetEncoding The encoding the string should be re-encoded into

canUseIconv()   X-Ref
Returns whether "iconv" can be used.

return: bool TRUE if "iconv" is available and can be used, FALSE otherwise

canUseMbString()   X-Ref
Returns whether "mb_string" functions can be used.
These functions come with the PHP Intl package.

return: bool TRUE if "mb_string" functions are available and can be used, FALSE otherwise