Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading text from external file

Status
Not open for further replies.

homeric

Technical User
Apr 23, 2000
65
0
0
Hi
When my web page is displayed I'd like it to read some text in from an external file, but I don't know how to do this - Can ayone help me please? - (for instance I'd like it to read in a fixed date from an external text file and display it in line with some existing text on my webpage - the read-in text could change from time to time)
Thanks
 
You can use a server side include (SSI) or a Server Side language such as PHP to read the file.

HTML alone cannot do this.

PHP:
echo("This is the date : ".include('path/to/myfile.txt'));

Code:
<p>Here is the date:
<!--#include virtual="path/to/myfile.txt" -->
</p>


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Hi

Just for completeness, you can include such content with JavaScript too. But that will not be part of the document, at least not as robots see it. So better listen to Foamcow.
JavaScript:
[b]function[/b] include(what)
{
  [b]var[/b] http=[b]new[/b] XMLHttpRequest()
  http.open([i]'GET'[/i],what,false)
  http.send(null)
  [b]if[/b] (http.readyState==4 && http.status==200) document.writeln(http.responseText)
}
Code:
This is the date : <script type="text/javascript">include('path/to/myfile.txt')</script>
Note that the above code is just a sample.

Feherke.
 
Feherke,

If I adapted your "javascript include" technique so that what was being included was a one line text file that contained an email address, would that be a viable method of hiding email address from robots and scrapers?

Just curious.

 
Hi

That will certainly reduce their success rate. I would say it should provide the same security as other JavaScript based obfuscations.

Some people sustain that search engine robots used to extract and request strings looking like URLs from the JavaScript code. So be sure you are not using full URLs :
Code:
<script type="text/javascript">include('[s][red][URL unfurl="true"]http://example.com/[/URL][/red][/s]path/to/myfile.txt')</script>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top