PHP: How to prevent url from being converted to HTML entities when using DOMDocument loadHTML

Viewed 44

I have the code below:

$html = '<!doctype html><html><head><meta charset="utf-8"></head><body><p>Hello <a href="https://www.example.com?<%= email%>">world</a></p></body></html>';
$doc = new \DOMDocument();
$doc->loadHTML($html);
print_r($doc->saveHTML());

It prints:

<!DOCTYPE html>
<html><head><meta charset="utf-8"></head><body><p>Hello <a href="https://www.example.com?&lt;%=%20email%&gt;">world</a></p></body></html>

But I need to keep the URL as it is in the href attribute: https://www.example.com?<%= email%> How to prevent the loadHTML to convert it to https://www.example.com?<%=%20email%&gt; ?

thanks

0 Answers
Related