Reputation:
<?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 ?
Upvotes: 2
Views: 930
Reputation: 8517
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).
Upvotes: 1
Reputation: 3990
Use <pre>
to format the text like that:
<?php
$mytext = <<<EOF
<pre>
test {
gl: 100;
mkd: 0;
sld: 0;
}</pre>
EOF;
echo $mytext;
?>
Upvotes: 2