<?php
$arr = [
'txt'=>"bla bla bla"
];
$var = json_encode($arr);
var_dump($var);
?>
<script>
const variable = JSON.parse('<?=$var?>');
console.log(variable);
</script>
<?php
$arr = [
'txt'=>"bla
bla
bla"
];
$var = json_encode($arr, JSON_UNESCAPED_LINE_TERMINATORS);
var_dump($var);
?>
<script>
const variable = JSON.parse('<?=$var?>');
console.log(variable);
</script>