Я пытаюсь создать слайд-шоу, которое представляет собой объединение HTML (этот HTML кодируется с помощью htmlentities($model->text,ENT_QUOTES, "UTF-8");)
и изображения. Но иногда HTML сложен, поэтому он ломается. Означает, что теги не в теге.
В приведенном ниже примере слайд-шоу перерыв для последнего.
<?php
$res_data = array(
array('type'=>1,'text'=>'https://www.pexels.com/photo/garden-landscaping-tourists-people-24823/'),
array('type'=>2,'text'=>'<p style="font-style:normal;margin:0px 0px 15px;padding:0px;text-align:justify;font-family:'Open Sans', Arial, sans-serif;font-size:14px;background-color:rgb(255,255,255);"><b>Lorem ipsum dolor sit amet</b>, consectetur adipiscing elit. Nunc aliquam, sem a sagittis pretium, nisl enim dictum ipsum, ac venenatis est nunc quis erat. Nam sit amet malesuada eros, eget tempus ligula. Aenean dignissim, massa vel lobortis ornare, sem mauris auctor mauris, vel ultrices libero lacus at lacus. Fusce lacinia elit nec nunc eleifend porta id a est. Nulla accumsan dignissim odio, quis mollis ipsum malesuada vel. Duis ut risus eleifend, vestibulum sem ac, condimentum tellus. Duis nec ex leo. Integer non lacus velit. Curabitur id lorem vitae tortor convallis efficitur sit amet at mauris. In suscipit mattis tempor. Vivamus risus nisi, dapibus elementum eros vel, ultrices cursus augue. Integer urna felis, pulvinar quis mollis posuere, sollicitudin quis turpis. Phasellus eget maximus purus, eget rhoncus arcu. Fusce mauris dui, scelerisque vitae condimentum sit amet, euismod volutpat sapien. Sed blandit nibh a eros euismod gravida. Sed consequat hendrerit sapien et cursus.</p><p style="margin:0px 0px 15px;padding:0px;text-align:justify;font-family:'Open Sans', Arial, sans-serif;font-size:14px;background-color:rgb(255,255,255);"><b><u><i>Morbi facilisis sed diam et tincidunt. Sed nisl purus, ornare ac ligula nec, dignissim commodo sem. Pr</i></u></b><span style="font-style:normal;font-weight:normal;">aesent vel elit dictum, consequat mauris a, placerat neque. Sed purus sem, imperdiet finibus libero eget, vehicula ultrices nisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent mollis nibh at nisi aliquet, sed fermentum dolor varius. Duis nunc nulla, accumsan non urna non, accumsan fringilla purus. Nam feugiat rutrum lectus quis bibendum. Nulla quis arcu orci. Sed iaculis nunc nisl, pulvinar imperdiet tortor varius in. Ut posuere felis quis dolor euismod malesuada. Suspendisse aliquam gravida tincidunt. In ac ligula nec ipsum tempus elementum nec nec est.</span></p>'),
array('type'=>2,'text'=>'<h2 style="margin:1em 0px;padding:0px;border:0px;font-size:18px;vertical-align:baseline;background:rgb(255,255,255);color:rgb(68,68,68);font-family:Arial, sans-serif;">Resources&nbsp;<a class="anchor" href="http://www.yiiframework.com/extension/cleditor#hh3" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;"></a></h2><p style="margin:0px 0px 20px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background:rgb(255,255,255);color:rgb(34,34,34);font-family:Arial, sans-serif;"><strong style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;">en-US</strong><br>*&nbsp;<a href="http://premiumsoftware.net/cleditor/index.html" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;">CLEditor resource page</a>. Plese follow to see available options.<br>*&nbsp;<a href="http://premiumsoftware.net/cleditor/index.html" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;">Try out a demo</a>, from author plugin.<br>*&nbsp;<a href="http://www.yiiframework.com/forum/index.php?showtopic=13121&amp;st=0" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;">Discussion &amp; Bug report</a>.</p><p style="margin:0px 0px 20px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background:rgb(255,255,255);color:rgb(34,34,34);font-family:Arial, sans-serif;"><strong style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;">pt-BR</strong><br>*&nbsp;<a href="http://premiumsoftware.net/cleditor/index.html" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;">CLEditor</a>. Siga este link para ver as opções disponives.<br>*&nbsp;<a href="http://premiumsoftware.net/cleditor/index.html" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;">Demonstração</a>, página do plugin do autor com exemplo.<br>*&nbsp;<a href="http://www.yiiframework.com/forum/index.php?showtopic=13121&amp;st=0" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent;color:rgb(0,153,204);text-decoration:none;">Discussão e Relato de Erros</a>.</p><p style="margin:0px 0px 20px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background:rgb(255,255,255);color:rgb(34,34,34);font-family:Arial, sans-serif;"><br></p><p style="margin:0px 0px 20px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background:rgb(255,255,255);color:rgb(34,34,34);font-family:Arial, sans-serif;"><u>DHaval</u></p>'),
);
foreach ($res_data as $res)
{
if($res['type']==1)
{
?>
<a class="popup_fancybox" rel="gallery1">
<img src="<?php echo $res['text']; ?>" alt="Image" />
</a>
<?php
}
elseif($res['type']==2)
{
?>
<a class="popup_fancybox" rel="gallery1">
<?php echo html_entity_decode($res['text']);?>
</a>
<?php
}
}
?>
<script>
$(document).ready(function () {
$ = jQuery.noConflict();
$(".popup_fancybox").fancybox({
autoPlay: true,
playSpeed: 1000,
openEffect: 'none',
closeEffect: 'none',
prevEffect: 'none',
nextEffect: 'none',
closeBtn: true,
loop: true,
}).click();
});
</script>
Пожалуйста, проверьте эту скрипку: http://jsfiddle.net/VNPzA/3699/
Как решить эту проблему?
Наконец, это решается с помощью ниже уловки:
Просто нужно изменить ниже
<a class="popup_fancybox" rel="gallery1">
<?php echo html_entity_decode($res['text']);?>
</a>
с
<div id="hid1" style="display:none">
<h3><?php echo $res['text'];?></h3>
<?php echo html_entity_decode($res['body_text'],ENT_QUOTES, "UTF-8");?>
</div>
<a class="popup_fancybox" rel="gallery1" href="#hid1">
</a>
Рабочая скрипка
Других решений пока нет …