Browse Source

Replace invalid xml utf-8 chars in tag contents.

drikc 4 years ago
parent
commit
ad76998ca5
2 changed files with 17 additions and 2 deletions
  1. 16
    1
      Feed.php
  2. 1
    1
      Item.php

+ 16
- 1
Feed.php View File

@@ -183,7 +183,7 @@ abstract class Feed
183 183
     */
184 184
     public function setChannelElement($elementName, $content, $attributes = null, $multiple = false)
185 185
     {
186
-        $entity['content'] = $content;
186
+        $entity['content'] = self::utf8_for_xml($content);
187 187
         $entity['attributes'] = $attributes;
188 188
 
189 189
         if ($multiple === TRUE)
@@ -564,6 +564,21 @@ abstract class Feed
564 564
 
565 565
         return $prefix . $uuid;
566 566
     }
567
+
568
+    /**
569
+    * Replace invalid xml utf-8 chars.
570
+    *
571
+    * See utf8_for_xml() function at
572
+    * http://www.phpwact.org/php/i18n/charsets#xml and
573
+    * http://www.w3.org/TR/REC-xml/#charsets
574
+    *
575
+    * @param    string
576
+    * @return   string
577
+    */
578
+    public static function utf8_for_xml($string)
579
+    {
580
+        return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
581
+    }
567 582
     // End # public functions ----------------------------------------------
568 583
 
569 584
     // Start # private functions ----------------------------------------------

+ 1
- 1
Item.php View File

@@ -95,7 +95,7 @@ class Item
95 95
         }
96 96
 
97 97
         $this->elements[$key]['name']       = $elementName;
98
-        $this->elements[$key]['content']    = $content;
98
+        $this->elements[$key]['content']    = Feed::utf8_for_xml($content);
99 99
         $this->elements[$key]['attributes'] = $attributes;
100 100
 
101 101
         return $this;

Loading…
Cancel
Save