Output file generated by bash to php page

There is a file that is created by the bash command $ script filename, where the commands entered into the terminal are written. I need this file to be displayed on a php page.
I did:

$text=file_get_contents("filename");  
$text=str_replace("\r\n","<br>",$text);  
print $text;

gives me:
alt text

There are extra characters “00;32ma” and the like. Everything before the starting interactive shell should be separated not by spaces, but by line breaks. I can replace “00;32ma” and other characters with str_replace, but I don’t know how to remove the squares. (

Is it possible to achieve readable output of this file and how?

UPDfile
UPD2something like thisshould look like (no extra characters, I mean)


Answer 1, authority 100%

To translate “\r\n” into “<br />” there is a function nl2br().

In general, it is likely that the square is the character “\x1b” try calling $text=str_replace("\x1b","",$text);, because “00;32ma” – part of the sequence for
setting the text color in the console.

About

Everything before the starting interactive shell should be separated by line breaks, not spaces.

Do this:

$tempText = exploade("======================================== starting interactive shell session", $text);
$tempText[0] = str_replace(" ", "<br />", $tempText[0]);
$text = implode("======================================== starting interactive shell session", $tempText);

Answer 2, authority 33%

Squares may appear if you have a utf-8 encoded file, and you output it to the browser, for example, windows-1251.