Rev 12 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 12 | Rev 15 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * XML Encoding Utilities |
4 | * XML Encoding Utilities |
5 | * Copyright 2011-2020 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2011-2020 Daniel Marschall, ViaThinkSoft |
6 | * Version 1.7.1 |
6 | * Version 1.7.2 (2020-12-06) |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 31... | Line 31... | ||
31 | # $str = mb_convert_encoding($str, 'UTF-8', 'auto'); |
31 | # $str = mb_convert_encoding($str, 'UTF-8', 'auto'); |
32 | $str = mb_convert_encoding($str, 'UTF-8'); |
32 | $str = mb_convert_encoding($str, 'UTF-8'); |
33 | } |
33 | } |
34 | 34 | ||
35 | // get rid of existing entities else double-escape |
35 | // get rid of existing entities else double-escape |
36 | // DM 24.08.2016 Auskommentiert wegen oid+ xml export |
36 | // DM 24.08.2016 Removed because of OIDplus 1.0 XML export |
37 | // $str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8'); |
37 | //$str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8'); |
38 | 38 | ||
39 | $ar = preg_split('/(?<!^)(?!$)/u', $str); // return array of every multi-byte character |
39 | $ar = preg_split('/(?<!^)(?!$)/u', $str); // return array of every multi-byte character |
40 | $str2 = ''; |
40 | $str2 = ''; |
41 | foreach ($ar as $c) { |
41 | foreach ($ar as $c) { |
Line 53... | Line 53... | ||
53 | if ($c == '<') $c = '<'; |
53 | if ($c == '<') $c = '<'; |
54 | if ($c == '>') $c = '>'; |
54 | if ($c == '>') $c = '>'; |
55 | if ($c == '=') $c = '='; |
55 | if ($c == '=') $c = '='; |
56 | if ($c == '"') $c = '"'; |
56 | if ($c == '"') $c = '"'; |
57 | if ($c == ''') $c = '\''; |
57 | if ($c == ''') $c = '\''; |
58 | if ($c == '&') $c = '&'; // DM 24.08.2016 Re-Aktiviert wegen oid+ xml export |
58 | if ($c == '&') $c = '&'; // DM 24.08.2016 Re-added because OIDplus 1.0 XML export |
59 | } |
59 | } |
60 | 60 | ||
61 | if (!$encode_linebreaks) { |
61 | if (!$encode_linebreaks) { |
62 | if ($allow_html) { |
62 | if ($allow_html) { |
63 | if ($c == " ") $c = "<br />"; |
63 | if ($c == " ") $c = "<br />"; |
Line 139... | Line 139... | ||
139 | } |
139 | } |
140 | return $dec; |
140 | return $dec; |
141 | } |
141 | } |
142 | 142 | ||
143 | function html_named_to_numeric_entities($str) { |
143 | function html_named_to_numeric_entities($str) { |
- | 144 | if (!mb_detect_encoding($str, 'UTF-8', true)) $str = utf8_encode($str); |
|
- | 145 | return mb_htmlentities(decodeNamedEntities($str)); |
|
- | 146 | } |
|
- | 147 | ||
144 | if (!function_exists('decodeNamedEntities')) { |
148 | if (!function_exists('decodeNamedEntities')) { |
145 | function decodeNamedEntities($string) { |
149 | function decodeNamedEntities($string) { |
146 | // https://stackoverflow.com/questions/20406599/how-to-encode-for-entity-igrave-not-defined-error-in-xml-feed |
150 | // https://stackoverflow.com/questions/20406599/how-to-encode-for-entity-igrave-not-defined-error-in-xml-feed |
147 | static $entities = NULL; |
151 | static $entities = NULL; |
148 | if (NULL === $entities) { |
152 | if (NULL === $entities) { |
Line 182... | Line 186... | ||
182 | return preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($match) use ($hex) { |
186 | return preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($match) use ($hex) { |
183 | return sprintf($hex ? '&#x%X;' : '&#%d;', mb_ord($match[0])); |
187 | return sprintf($hex ? '&#x%X;' : '&#%d;', mb_ord($match[0])); |
184 | }, $string); |
188 | }, $string); |
185 | } |
189 | } |
186 | } |
190 | } |
187 | - | ||
188 | if (!mb_detect_encoding($str, 'UTF-8', true)) $str = utf8_encode($str); |
- | |
189 | return mb_htmlentities(decodeNamedEntities($str)); |
- | |
190 | } |
- |