Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

(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.

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

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

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

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

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

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

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

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.

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
return: string The converted string, encoded with the given encoding

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