-
Notifications
You must be signed in to change notification settings - Fork 750
Open
Description
Hello,
I have resolved a problem in the TextParser.php
This is the resolution for me, if this can help anyone...
In : src/Parsing/TextParser.php
<?php
namespace Spipu\Html2Pdf\Parsing;
/**
* Class TextParser
*/
class TextParser
{
/**
* @var string
*/
private $encoding;
/**
* @param string $encoding
*/
public function __construct($encoding = 'UTF-8')
{
$this->encoding = $encoding;
}
/**
* prepare the text
*
* @param string $txt
* @param boolean $spaces true => replace multiple space+\t+\r+\n by a single space
* @return string txt
* @access protected
*/
public function prepareTxt($txt, $spaces = true)
{
// Test de l'encodage
$is_unicode_encoding = false;
// Vérification si l'encodage est un encodage Unicode comme UTF-8 ou UTF-16
if (in_array(strtoupper($this->encoding), ['UTF-8', 'UTF-16', 'UTF-32'])) {
$is_unicode_encoding = true;
}
// Gestion des espaces
if ($spaces) {
if ($is_unicode_encoding) {
// Pour un encodage Unicode (UTF-8, UTF-16, etc.)
$txt = preg_replace('/\s+/isu', ' ', $txt); // Avec le modificateur 'u' pour Unicode
} else {
// Pour les encodages non-Unicode (ISO-8859-1, etc.)
$txt = preg_replace('/\s+/is', ' ', $txt); // Sans 'u' pour éviter les erreurs de gestion d'Unicode
}
}
// Remplacer l'entité euro (si elle existe)
$txt = str_replace('€', '€', $txt);
// Décoder les entités HTML dans l'encodage spécifié
$txt = html_entity_decode($txt, ENT_QUOTES, $this->encoding);
return $txt;
}
}Metadata
Metadata
Assignees
Labels
No labels