...

View Full Version : importing text



jfreak53
05-26-2004, 10:31 PM
I need a way to import plain text from a text file using Javascript or another easy way, so as not to blog down my site with ASP or other things, so I can import just one line of text from a TXT file to a place in my html file, so I can daily update something with having to do the whole file and multiple files.

liorean
05-26-2004, 10:40 PM
If you're talking about reading a file on the server from JavaScript, have a look in the FAQ. Was that what you meant? Or did you mean importing to the server from the client? If so, a serverside technology is required.

sad69
05-26-2004, 10:41 PM
One way to do it could be like this: (2 files)

index.html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>

<script language="JavaScript" type="text/javascript" src="myfile.js">
</script>

</body>
</html>


my_text.js


var myMsg = "Hello World!";
document.write(myMsg);


So now you can update my_text.js daily, and just change the value of myMsg. If that's not adequate, let me know. But I think that's the easiest way I can think of...

Also, on the index.html page, the place the script tags with that src wherever you'd like on your page.

Hope that helps,
Sadiq.

jfreak53
05-26-2004, 10:41 PM
I only need to read localy from the server onto my web page. What FAQ are you talking about?

Antoniohawk
05-26-2004, 10:51 PM
[http://www.codingforums.com/showthread.php?p=178912#post178912]

jfreak53
05-26-2004, 11:31 PM
That javascript version works just great, one more things though, maybe this has to do with ASP or PHP, but is there a way to take information from another page and place it here to cut down on my work?

sad69
05-26-2004, 11:43 PM
That javascript version works just great, one more things though, maybe this has to do with ASP or PHP, but is there a way to take information from another page and place it here to cut down on my work?

Care to elaborate on that a little more? Like who owns that information? Was it created by you and resides on your server, or by someone else somewhere else?

Is it just a sentence on some page, a paragraph, or the whole page? If it's your page on your server, and just a sentence or a paragraph, you can just put that sentence/paragraph in a separate file (like how we did in my first post) and then you can include it in the original file AND in your new file (so the data is in one place, but viewed in two).

If it's some data on some other page on a different server altogether, then it's a server-side language issue. I don't know much about ASP, but using PHP you can use cURL or Snoopy to grab the contents of a web page, and then regular expressions to grab the particular data from that page. This is a bit trickier, so hopefully it's your own page on your own server.

So let us know what you're looking to do exactly..

Sadiq.

jfreak53
05-26-2004, 11:52 PM
The information is on another page, just text, but from what I can see, there pages are ASPX, which doesn't that mean they take it from a database?

sad69
05-26-2004, 11:55 PM
I don't know, but it doesn't necessarily mean it's from a database..

Regardless, if you do a view source, can you see the text that you want? If so, then you can use cURL or Snoopy (PHP) to grab that text. ASP probably has some method of doing this also, I'm just unaware of it.

If you can't see it in the view source, you might be out of luck.

Sadiq.

jfreak53
05-26-2004, 11:58 PM
Ok, sounds easy enough, just one thing the text is constantly changing, every day, it's stock quotes on coffee for every day, how would I grab this? I already checked out the source, and from the looks of things it's just plain text, but I don't think they change a whole page everyday as well. Also where do I get some info on Snoopy or cURL?

sad69
05-27-2004, 12:23 AM
You should look at this page everyday, and save the source of each day and then analyze it and figure out how you know what the data is so you can create some regular expressions to capture your data.

But if it's just stock quotes, Yahoo provides a 'web service' so that you can grab quotes off their page. Here's a link to a tutorial on how to do it using PHP:
http://tutorials.programmingsite.co.uk/yahoocsv.php

Hope that helps,
Sadiq.

jfreak53
05-27-2004, 06:05 AM
Well this is great and it works fine, but my problem is I don't need to know what one sole company did, but I need to know how coffee is priced in general in the NY Stock Exchange?

jfreak53
05-27-2004, 06:20 AM
This is the site I'm try to grab from, I know it's grabbing from somewhere else because the images are in english:

http://portal.anacafe.org/Portal/DesktopModules/PreciosCafeDetalle.aspx?StockID=1

sad69
05-27-2004, 06:34 AM
I dunno, it looks like it might be a bit tricky. You're gonna need some hacking skills!

Well you should probably start posting in the PHP forums and explain your problem again. They'll be able to help you better over there.

Here's a link that might be helpful in learning this stuff:
http://www.tutorialized.com/tutorials/PHP/Web-Fetching/1

Sorry I can't be of more assistance.

PS. It couldn't hurt to ask the website where they're grabbing the information from, could it? Might save you some time maybe... or not ;)

Sadiq.

jfreak53
05-27-2004, 05:22 PM
Well I thought of asking them last night and all it actually came to mind, I might try it out... :thumbsup: Thanks for all your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum