سؤال

<?php

$mytext = <<<EOF
test {
    gl: 100;
    mkd: 0;
    sld: 0;
}
EOF;



echo $mytext;

?>

the output is :

test { aaa: black; bbb: yellow; ccc: red; }

and I want the output exactly how it's wrote inside the eof segments.

test {
    gl: 100;
    mkd: 0;
    sld: 0;
}

Any idea ?

هل كانت مفيدة؟

المحلول

Use <pre> to format the text like that:

<?php

$mytext = <<<EOF
<pre>
test {
    gl: 100;
    mkd: 0;
    sld: 0;
}</pre>
EOF;



echo $mytext;

?>

نصائح أخرى

Browser usually ignores control characters, like whitespaces in HTML.

Another solution would be using echo(nl2br($mytext)) instead. Which would convert all \n into <br />.

Converting manually might help You dealing with another kind of whitespaces. Something like this:

$replacee = array("\n", "\t");
$replacement = array("<br />", "    ");
$mytext = str_replace($replacee, $replacement, $mytext);

Really similar problem linked here and here (mostly client side solutions).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top