javascript – Is there any way to take a one line txt file and copy its text to an html paragraph?-ThrowExceptions

Exception or error:

I want to be able to put the text of this .txt file on my page and have the ability to format it using css, I already tried using but I couldn’t figure out how to format this text, and all the other solutions I found were much more complicated for what I need, does anyone have any idea what I can do?

How to solve:

Not sure of any ways using just javascript, but here’s a way (using PHP) that you can do that.

Say this is your txt file, main.txt:

This is txt text

This would be your main php file, main.php:

<span class="mycontent">
<?php
$text = file_get_contents("main.txt");
echo $text;
?>
</span>

And this would be your css:

.mycontent {
/* Desired styles here */
}

If you aren’t familiar with how to use PHP, you can download XAMPP or MAMP which are basically Apache (PHP running) servers that you download onto your computer.

Hope that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *