Jump to content

[SOLVED] Reading Files


schme16

Recommended Posts

i've scoured the net and all i can find is ways to read XML data, but people keep saying its easy to get the contents of a txt file (the file is on the server that the script will be launched from...i was informed that it cannot be done otherwise) but no-one will sya how its done....

 

 

 

 

 

Thanks in advance for any help!

Link to comment
https://forums.phpfreaks.com/topic/49798-solved-reading-files/
Share on other sites

Just as you request an XML file from the server with JavaScript, you can also request a text file.  Technically you can request anything the server is willing to return.  What JS gives you is a built-in XML parser.  But you can use string functions, regex, etc, to get info out of anything, including a txt file.

Link to comment
https://forums.phpfreaks.com/topic/49798-solved-reading-files/#findComment-244294
Share on other sites

I think the easiest way to read a  text file through iframe. Just call the text file in a hidden iframe and read the content using a script. Here is a quick example

<script language="javascript">
var did_load=false;
function grap_cont(){
	if (did_load){
		var frm = document.getElementById('hidden_frame').contentWindow.document;

		var txt = frm.body.innerHTML.replace(/<[^>]*>/g,"");

		alert(txt);
	}
}
</script>
<a href="txt1.txt" target="hidden_frame">First text file</a><br />
<a href="txt2.txt" target="hidden_frame">Second text file</a>
<iframe src="blank.html" name="hidden_frame" id="hidden_frame" onload="grap_cont(); did_load=true;" style="width:0px; height:0px;" frameborder="0" scrolling="no"></iframe>

Link to comment
https://forums.phpfreaks.com/topic/49798-solved-reading-files/#findComment-244493
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.