I have trouble while rendering display article for look beautifull. Saving article have sanitize with used trim(stripslashes($article));
And I want to display article use HTML code by parse saving before, the goal is easy and comfort to read article.
in Article controller
public function view($id = null)
{
$article = $this->Articles->get($id, [
'contain' => ['Users', 'Comments', 'Tags']
]);
$parsearticle = $this->Articles->find()->extract('Isi');
return $this->response
->withType('application/json')
->withStringBody(json_encode([
'parseHTML' => $parsearticle,
]));
$this->set('article', $article);
}
in method
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
{
foreach($data as $key => $article) {
if(is_string($article)) {
$data[$key] = trim(stripslashes($article));
}
}
}
in ctp
<div id="parseHTML">
</div>
<p>
<?php echo $this->Text->autoParagraph(h($article->Isi))."\n"; ?>
</p>
<!-- parser HTML -->
<script type="text/javascript">
jQuery(document).ready(function() {
var tampil = $("#parseHTML");
var parse = '<?= Router::url(["controller" => "articles","action" => "view"]); ?>';
var konv = $.parseHTML(parse);
$.ajax({
type:'post',
url:parse,
data:'&type=parseHTML',
dataType:'json',
success:function(){
tampil.append(konv);
});
});
</script>
<!-- //parser HTML -->
the error shown display below
0 "kebersihan kandang harus dijaga"
1 "penyakit ini sangat berbahaya, perhatikan kebersihan lingkungan pengobatan vaksinnya membutuhkan aktu lama. Penyakit ini menimbulkan cacat janin"
2 "penyakit ini disebabkan jamur, jamur toxic ini banyak tersebar di tempat jorok dan kumuh"
3 "penyakit ini disebabkan jamur, jamur ini banyak tersebar di tempat-tempat jorok"
4 "kucing harus dirawat, sebagai tanda kebersihan pemiliknya juga"
5 "<p><span style=\"backgro…izen<br></font>s<br></p>"
6 "<p><font color=\"#000000\"><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"58\">Selamat malam semuanya</span></font></p><p><font color=\"#000000\"><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"57\"><br></span></font></p><table class=\"table table-bordered\"><tbody><tr><td><font color=\"#000000\">Nama</font><br></td><td>l<font color=\"#000000\">Alamat</font><br></td></tr><tr><td><font color=\"#000000\">Aris Setiawan</font><br></td><td><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"56\"><font color=\"#000000\">Tangerang</font></span><br></td></tr></tbody></table><p><font color=\"#000000\"><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"55\"><br></span></font><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"54\"><font color=\"#000000\">Kita semua pernah <u>memelihara</u> <b>kucing</b> yah, jangan lupa dijaga kebersihannya<br></font></span></p><p><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"53\"><font color=\"#000000\"><br></font></span></p><p><span style=\"background-color: rgb(255, 255, 255);\" wfd-id=\"52\"><font color=\"#000000\"><br></font></span><br></p>"
7 "<blockquote><p><span style=\"background-color: rgb(247, 198, 206);\"><font color=\"#000000\">Merawat Bulu Kucing Itu Sangat Mudah</font></span></p></blockquote><p><font color=\"#000000\"><br></font></p><p style=\"margin-left: 25px;\"><font color=\"#000000\">Seperti manusia yang merawat rambutnya dengan penuh perhatian, secara rutin saat mandi dikeramasin, dishampoin.</font></p><p style=\"\"><font color=\"#000000\">Pun begitu kepada binatang peliharaan kesayangan kita kucing, juga harus dirawat bulu-bulunya, jangan dibiarkan rontok,</font></p><p style=\"\"><font color=\"#000000\">banyak kutunya, bulu-bulunya bau apek penuh debu.</font></p><p style=\"\"><font color=\"#000000\"><br></font></p><p style=\"margin-left: 25px;\"><font color=\"#000000\">Cara merawat bulu kucing, yaitu rutin dikeramasin, rutin disisirin, rutin diberi wangi2-an, rutin diberi antiseptik. Insya Allah</font></p><p style=\"\"><font color=\"#000000\">kucing itu jadi terlihat bersih, lucu dan imut<br></font><br></p>"
thanx for want to help me