FIX_CLAIM_CONVERSATION_TEXT_REMOVE_HTML_TAGS
This commit is contained in:
parent
7884681d47
commit
3586c856ee
@ -26,6 +26,7 @@ use App\Models\VehicleModel;
|
||||
use App\Models\PartnerPolicyModel;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Kint\Kint;
|
||||
|
||||
@ -1313,7 +1314,7 @@ class TicketController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function convertHtmlToText($html)
|
||||
public function convertHtmlToTextOld($html)
|
||||
{
|
||||
if(!empty($html)){
|
||||
$dom = new DOMDocument();
|
||||
@ -1324,6 +1325,36 @@ class TicketController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function convertHtmlToText($html)
|
||||
{
|
||||
if (empty($html)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Remove BOM / strange characters
|
||||
$html = preg_replace('/[\x00-\x1F\x80-\xFF]/', ' ', $html);
|
||||
|
||||
// Load HTML safely
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
|
||||
|
||||
// Remove style and script tags
|
||||
$xpath = new DOMXPath($dom);
|
||||
foreach ($xpath->query('//style|//script') as $node) {
|
||||
$node->parentNode->removeChild($node);
|
||||
}
|
||||
|
||||
// Extract clean text
|
||||
$text = $dom->textContent;
|
||||
|
||||
// Clean extra spaces
|
||||
$text = preg_replace('/\s+/', ' ', $text);
|
||||
|
||||
return trim($text);
|
||||
}
|
||||
|
||||
|
||||
public function removeTicket()
|
||||
{
|
||||
$ticket_id = $this->request->getGet('ticket_id');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user