Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########## |
| 2 | XML Helper |
| 3 | ########## |
| 4 | |
| 5 | The XML Helper file contains functions that assist in working with XML |
| 6 | data. |
| 7 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 8 | .. contents:: |
| 9 | :local: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 10 | |
Derek Jones | 65d4f7e | 2013-07-19 15:35:36 -0700 | [diff] [blame] | 11 | .. raw:: html |
| 12 | |
| 13 | <div class="custom-index container"></div> |
| 14 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 15 | Loading this Helper |
| 16 | =================== |
| 17 | |
| 18 | This helper is loaded using the following code |
| 19 | |
| 20 | :: |
| 21 | |
| 22 | $this->load->helper('xml'); |
| 23 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 24 | Available Functions |
| 25 | =================== |
| 26 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 27 | The following functions are available: |
| 28 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 29 | .. php:function:: xml_convert($str[, $protect_all = FALSE]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 30 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 31 | :param string $str: the text string to convert |
| 32 | :param bool $protect_all: Whether to protect all content that looks like a potential entity instead of just numbered entities, e.g. &foo; |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 33 | :returns: XML-converted string |
| 34 | :rtype: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 35 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 36 | Takes a string as input and converts the following reserved XML |
| 37 | characters to entities: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 38 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 39 | - Ampersands: & |
| 40 | - Less than and greater than characters: < > |
| 41 | - Single and double quotes: ' " |
| 42 | - Dashes: - |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 43 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 44 | This function ignores ampersands if they are part of existing numbered |
| 45 | character entities, e.g. {. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 46 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 47 | $string = '<p>Here is a paragraph & an entity ({).</p>'; |
| 48 | $string = xml_convert($string); |
| 49 | echo $string; |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 50 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 51 | outputs: |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 52 | |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 53 | .. code-block:: html |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 54 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 55 | <p>Here is a paragraph & an entity ({).</p> |