Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15

Thread: importing text

  1. #1
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts

    importing text

    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.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One way to do it could be like this: (2 files)

    index.html
    Code:
    <!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
    Code:
    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.

  • #4
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    I only need to read localy from the server onto my web page. What FAQ are you talking about?

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts

  • #6
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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?

  • #7
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jfreak53
    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.

  • #8
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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?

  • #9
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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?

  • #11
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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?

  • #13
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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/Des...aspx?StockID=1

  • #14
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/tutorial...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.

  • #15
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Well I thought of asking them last night and all it actually came to mind, I might try it out... Thanks for all your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •