@ 2018-06-20T11:49:57Z <?php
$html = <<<EOD
<p>С этой формы приходят заявки <a href="https://site.com/lack_tech.php">https://site.com/lack_tech.php</a></p>
<p>Или что ты имеешь ввиду?</p>
<div class="attachment_files_message">
<p>Прикреплённые файлы:</p>
<a href="http://site.com/public/uploads/kylticket/2670/Screenshot_1.png" target="_blank">Screenshot_1.png</a>
</div>
EOD;
$dom = new DOMDocument();
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//a[@target="_blank"]') as $OurNode) {
if (preg_match('~\.(?:jpe?g|png)$~i', $OurNode->getAttribute('href'))) {
$fragment = $dom->createDocumentFragment();
$aNode = $dom->createElement('a');
$aNode->setAttribute('data-fancybox', 'gallery'); // + data-fancybox
$aNode->nodeValue = '';
$aNode->setAttribute('href', $OurNode->getAttribute('href'));
$img = $dom->createElement('img');
$img->setAttribute("src", $OurNode->getAttribute('href'));
$img->setAttribute("alt", "");
$img->setAttribute("class", "tmp_class");
$aNode->appendChild($img);
$fragment->appendChild($aNode);
$OurNode->parentNode->replaceChild($fragment, $OurNode);
}
}
echo mb_convert_encoding($dom->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /in/lEBZO on line 13
<p>С этой формы приходят заявки <a href="https://site.com/lack_tech.php">https://site.com/lack_tech.php</a><p>Или что ты имеешь ввиду?</p><div class="attachment_files_message">
<p>Прикреплённые файлы:</p>
<a data-fancybox="gallery" href="http://site.com/public/uploads/kylticket/2670/Screenshot_1.png"><img src="http://site.com/public/uploads/kylticket/2670/Screenshot_1.png" alt="" class="tmp_class"></a>
</div></p>
Output for 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.33 <p>С этой формы приходят заявки <a href="https://site.com/lack_tech.php">https://site.com/lack_tech.php</a><p>Или что ты имеешь ввиду?</p><div class="attachment_files_message">
<p>Прикреплённые файлы:</p>
<a data-fancybox="gallery" href="http://site.com/public/uploads/kylticket/2670/Screenshot_1.png"><img src="http://site.com/public/uploads/kylticket/2670/Screenshot_1.png" alt="" class="tmp_class"></a>
</div></p>
preferences:dark mode live preview ace vim emacs key bindings
137.54 ms | 410 KiB | 5 Q