A
A
Andrey Golubkov2016-06-18 22:07:23
PHP
Andrey Golubkov, 2016-06-18 22:07:23

How to properly output source code from a file?

The server contains text files of formatted source code.
Script that produces the file:

<?php
$file = $_GET["code"].'.txt';
$text = file_get_contents($file);
echo nl2br( $text );
?>

I get the file like this:
$http({
      method: 'GET',
      url: url+'code.php?code='+item.path
    }).then(function successCallback(response) {
      $scope.SRCCode.code = response.data;
    }, function errorCallback(response) {
      });

I put it on the screen like this:
<code class=" language-cpp">
    {{SRCCode.code}}

It turns out that all the code is in one line, and in the file it is formatted.
How can I make it so that the file would be output in a normal way.
58362875bb40479e8f022bfe6a7f7b39.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daemon23RUS, 2016-06-18
@Daemon23RUS

Try echo nl2br( $text );to replace with echo $text;
and output through the tag <pre>
, it looks like you are shielded during the output <br/>
as a bonus, save the formatting with spaces ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question