loading...

re: Elegant code in PHP VIEW POST

FULL DISCUSSION
 

My code for this:

<?php

$doc = new \DOMDocument('1.0', 'UTF-8');
$name = $_POST['name'] ?? null;
$data = new \DOMElement('data', $name);
$doc->appendChild($data);
$xslt = new \XSLTProcessor();
$template = new \DOMDocument();
$template->load('template.xsl');
$xslt->importStylesheet($template);
echo $xslt->transformToXml($doc);

For $name=="<script>alert('Hello')</script>"; will output:

<div>&lt;script&gt;alert('Hello')&lt;/script&gt; is nice name</div>

How will look your output?

code of conduct - report abuse