There is a text file with some content, I shove it into a div using js (innerHTML). Here is an example:

var inside = '<?php include("main.txt");?>'; 

In general, the problem is this: if the content in the text file is not located in one line, then s adds an apostrophe to the beginning of the text and gives the error "unterminated string literal". How to get out of a predicament?

    1 answer 1

    Something like this:

      var inside = '<?= str_replace("\n", "\\\n", file_get_contents("main.txt")) ?>'; 

    I will add that, for good, this is also not enough. if there is a single quote in the text file, this will also lead to an error.

    I would not use PHP at all, do I need the contents of a text file? Ajax to help, IMHO this approach is terrible

    • So did, thank you. At first it did not work, it turned out that it was necessary not to write \ n, but \ r to write. Just in case, I am changing both \ n and \ r to <br> - Max Kozhanov