WeSee :
I need to assign large strings in an array. These strings contain single and double quotes as well as backslashes which cannot be escaped at first.
My code looks like:
$myArray = [
'x' => 'this_is_my_string',
];
Now instead of 'this_is_my_string'
I have large strings as:
\relative c' {
\key ees \major
bes'2 \mf c bes4. (as8) g4 (as) \breathe
\bar "|."
How to write my code to directly assign large strings like this one?
I have tried with HEREDOC and NOWDOC and addslashes/addcslashed but they require to escape at least one of ´
or "
.
BTW: the large strings are Lilypond snippets
Scoots :
You're looking for Output Buffering.
<?php
ob_start();
?>\relative c' {
\key ees \major
bes'2 \mf c bes4. (as8) g4 (as) \breathe
\bar "|."<?php
$myArray = [
'x' => ob_get_clean()
];
?>
ob_start()
initialises output buffering, redirecting STDOUT to the buffer. ob_end_clean()
will end output buffering, and return the buffer up to that point for use.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=346324&siteId=1