I converted array to json to use data. I got error when there is break line in array.
Here is my code:
<script>
function showKnowledgeItem(id) {
var title = [];
var text = [];
<?php
$query = (new \yii\db\Query())
->select('')
->from('fc_knowledge')
->all();
$arr = array();
$arr = json_encode($query, true);
$json_output = json_decode($arr);
foreach ($json_output as $title) {
?>
title [<?= $title->id ?>] = ["<?= $title->title ?>"];
<?php
}
foreach ($json_output as $content) {
?>
text [<?= $content->id ?>] = ["<?= $content->content ?>"];
<?php
}
?>
}
</script>
This code works well. But when there is new line or break line in the array, it does not work.
The error obvious in this picture:
Does anyone knows what I have to solve this problem. Tank you so much.