Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 402 and 403]

(no description)

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

Defines 1 class

EncodingHelper:: (7 methods):
  __construct()
  factory()
  getBytesOffsetToSkipBOM()
  attemptConversionToUTF8()
  attemptConversionFromUTF8()
  hasBOM()
  attemptConversion()


Class: EncodingHelper  - X-Ref


__construct(bool $canUseIconv, bool $canUseMbString)   X-Ref
No description

factory()   X-Ref
No description

getBytesOffsetToSkipBOM($filePointer, string $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)

attemptConversionToUTF8(?string $string, 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 $string, 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

hasBOM($filePointer, string $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

attemptConversion(?string $string, string $sourceEncoding, string $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