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 401 and 402] [Versions 401 and 403]

(no description)

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

Defines 1 class

Charset:: (6 methods):
  instance()
  __construct()
  buildConversionTable()
  encodeEntities()
  isValidCharset()
  getEntities()


Class: Charset  - X-Ref


instance()   X-Ref
This class is singleton for performance reasons.

return: Charset

__construct()   X-Ref
Force usage as singleton


buildConversionTable($tableName)   X-Ref

param: string $tableName

encodeEntities($data, $srcEncoding = '', $destEncoding = '')   X-Ref
Convert a string to the correct XML representation in a target charset.
This involves:
- character transformation for all characters which have a different representation in source and dest charsets
- using 'charset entity' representation for all characters which are outside of the target charset

To help correct communication of non-ascii chars inside strings, regardless of the charset used when sending
requests, parsing them, sending responses and parsing responses, an option is to convert all non-ascii chars
present in the message into their equivalent 'charset entity'. Charset entities enumerated this way are
independent of the charset encoding used to transmit them, and all XML parsers are bound to understand them.

Note that when not sending a charset encoding mime type along with http headers, we are bound by RFC 3023 to emit
strict us-ascii for 'text/xml' payloads (but we should review RFC 7303, which seems to have changed the rules...)

param: string $data
param: string $srcEncoding
param: string $destEncoding
return: string

isValidCharset($encoding, $validList)   X-Ref
Checks if a given charset encoding is present in a list of encodings or if it is a valid subset of any encoding
in the list.

param: string $encoding charset to be tested
param: string|array $validList comma separated list of valid charsets (or array of charsets)
return: bool

getEntities($charset)   X-Ref
Used only for backwards compatibility

param: string $charset
return: array