XmlEncoder.php in Feeds extensible parsers 8
File
src/Encoder/XmlEncoder.php
View source
<?php
namespace Drupal\feeds_ex\Encoder;
class XmlEncoder extends TextEncoder {
protected $findRegex = '/^<\\?xml[^>]+encoding\\s*=\\s*("|\')([\\w-]+)(\\1)/';
protected $replaceRegex = '/^(<\\?xml[^>]+encoding\\s*=\\s*("|\'))([\\w-]+)(\\2)/';
protected $replacePattern = '$1UTF-8$4';
public function convertEncoding($data) {
$matches = FALSE;
$encoding = 'ascii';
if (preg_match($this->findRegex, $data, $matches)) {
$encoding = $matches[2];
}
elseif ($detected = $this
->detectEncoding($data)) {
$encoding = $detected;
}
if (in_array(strtolower($encoding), self::$utf8Compatible)) {
return $data;
}
$data = $this
->doConvert($data, $encoding);
if ($matches) {
$data = preg_replace($this->replaceRegex, $this->replacePattern, $data);
}
return $data;
}
}
Classes
Name |
Description |
XmlEncoder |
Converts the encoding of an XML document to UTF-8. |