How to insert your file path in the document.documentElement.innerHTML?

Hi all. I want to make a code display with synaxiom.
Found the library, all is well. But the problem is.
document.documentElement.innerHTML - displays the code of your page.
How to do to display the innerHTML code of the file I want to specify?
That is, I pass the file path using the GET parameter in php. And how can I make the contents of this file with innerHTML?

I also understand that .innerHTML can output not only html contents but also php and other languages?
July 12th 19 at 16:53
3 answers
July 12th 19 at 16:55
Solution
You have something confused. document.documentElement.it's innerHTML on the client (only), and php is on the server (only).

Read the desired file on the server, do htmlspecialchars and sends to the browser. And there already format the client library code.
About the client and the server I know.
I tried to deduce through htmlspecialchars, but without success.
<?php
$text1 = file_get_contents( $_GET['urledit']);
$text = htmlspecialchars($text1); 
?>
the <script>
window.onload = function() {
 editor = CodeMirror(document.getElementById("editor"), {
 value: "<?php echo $text;?> ",
 mode: "text",
 matchTags: {bothTags: true},
 extraKeys: {"Ctrl-J": "toMatchingTag"}
});
};
 </script>
- wiley_Torphy70 commented on July 12th 19 at 16:58
<textarea class="js-cm-code"><?=$text?></textarea>
the <script>
var cm = CodeMirror.fromTextArea(
$('.js-cm-code').get(0),
{
 mode : 'text',
}
);
</script>
- amalia_Barrows22 commented on July 12th 19 at 17:01
Yes, but the backlight is not present, unfortunately! - wiley_Torphy70 commented on July 12th 19 at 17:04
Well $text1 = file_get_contents( $_GET['urledit']); this is of course Resecure - amalia_Barrows22 commented on July 12th 19 at 17:07
: mode to install Codemirror not realize that the source he slipped - amalia_Barrows22 commented on July 12th 19 at 17:10
Anyway. Just displays! - wiley_Torphy70 commented on July 12th 19 at 17:13
: jsbin.com/yakudiyaqa/edit?html,js,output - amalia_Barrows22 commented on July 12th 19 at 17:16
: Thanks, I will look, but not today! - wiley_Torphy70 commented on July 12th 19 at 17:19
: Great, thank you what you need. And how does it work, what scripts are working there, can any comments? - wiley_Torphy70 commented on July 12th 19 at 17:22
July 12th 19 at 16:57
php.net/manual/ru/function.highlight-file.php
<?php
echo highlight_file($_GET['f'])
?>

Caution
You must use the function highlight_file() with proper attention, so as not inadvertently to disclose confidential information, such as passwords or any other information that can create potential security risks.
July 12th 19 at 16:59
Duck what's the problem? Ajax call to some file (in php), pass it the options you want (if you want), suspended colback and his body is already treated some tag on the page and it should print the contents of this file:

$.ajax ({

 'method': 'get',
 'url': 'http://ваш_сайт/my-file.php',
 'data': { array of parameters optional },
 'success': function (content) {
 $('#mytag').html (content);
},

});

Pre-insert on the page code

<div id="mytag"></div>

And my-file.php put your highlight_file () or whatever you need via echo. JS - it's just a gasket, he gets nothing, it can only the contents of colbeck stuck in him.

Find more questions by tags PHP