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

(no description)

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

Defines 1 class

Charset:: (7 methods):
  instance()
  __construct()
  buildConversionTable()
  encodeEntities()
  knownCharsets()
  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
return: void

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

knownCharsets()   X-Ref
No description

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 (the .inc shims).

param: string $charset
return: array