HTML is not a programming language. It's a markup language. It simply describes how things should look and be laid out on a webpage.
PHP is a programming language, not a markup language. It performs logic and is able to process files and other things.
You'll need both, combined, to do what you'd like. And there are plenty of good HTML+PHP tutorials out there to help you. Search google and here for that.
This will get you each line in file: //www.ibm.com/developerworks/library/os-php-readfiles/
After that, it's up to you to format and parse it how you want. I suggest spending some time on php.net [//php.net/manual/en/tutorial.php] or searching google for information. Someone has done what you want, I'm almost positive.
EDIT:
;
This doesn't work because it tells PHP to put what ever the contents of version.txt is into the script tags of the page, or more importantly, to put it exactly where you're calling the PHP code from.
For it to be displayed, the content that PHP generates in the areas of the code has to be inside of HTML tags that will eventually display.
For instance:
;
Because the HTML tag is supposed to contain
invisible javascript code, whereas the
is a generic tag meant to hold visible content. Your example doesn't work because it's putting all of that output in the invisible parts of the page instead of the visible ones.
View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
HTML 5 provides a standard way to interact with local files with the help of File API. The File API allows interaction with single, multiple as well as BLOB files. The FileReader API can be used to read a file asynchronously in collaboration with JavaScript event handling. However, all the browsers do not have HTML 5 support so it is important to test the browser compatibility before using the File API. There are four inbuilt methods in the FileReader API to read local files:
- FileReader.readAsArrayBuffer[]: Reads the contents of the specified input file. The result attribute contains an ArrayBuffer representing the file’s data.
- FileReader.readAsBinaryString[]: Reads the contents of the specified input file. The result attribute contains the raw binary data from the file as a string.
- FileReader.readAsDataURL[]: Reads the contents of the specified input file. The result attribute contains a URL representing the file’s data.
- FileReader.readAsText[]: Reads the contents of the specified input file. The result attribute contains the contents of the file as a text string. This method can take encoding version as the second argument[if required]. The default encoding is UTF-8.
In this case we are using FileReader.readAsText[] method to read local .txt file.
Read Text File
document.getElementById[
'inputfile'
]
.addEventListener[
'change'
,
function
[] {
var
fr=
new
FileReader[];
fr.onload=
function
[]{
document.getElementById[
'output'
]
.textContent=fr.result;
}
fr.readAsText[
this
.files[0]];
}]
This code prints the content of the input file exactly the same as is there in the input file.
JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.