www.webdeveloper.com
Results 1 to 14 of 14

Thread: text from a txt file

  1. #1
    Join Date
    Jun 2006
    Posts
    23

    Post text from a txt file

    Hi
    I have a txt file, and i need to put the text in the web site calling it from the txt. I donīt want to call a txt file with frames o something like that i need it to be in a table, in a cell. can i do it?? can i do it with javascript? can i do something similar?

    Thanks

  2. #2
    Join Date
    Jul 2003
    Location
    New York City
    Posts
    2,771
    Sever side scripting would be your best bet. I would go for that, it's much more reliable, especially if this is the content of your page and not just an extra. You never want to rely on javascript, since not everyone has it. You can do this with Javascript, but I wouldn't recommend it unless this text was merely an extra, non-essential part of the page.

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    Depending upon what you want to display in the '.txt' file, you could read information in as a javascript string with a few modifications and change the extension to '.js'

    Then you can write as part of the document.write() function
    OR
    Open a new window and display text in popup
    OR
    Transfer to a <textarea> if the information needed to be edited prior to printing.

    I'm just not sure what you want to do from your question so the server-side option may be better.

  4. #4
    Join Date
    Jun 2006
    Posts
    23
    Thenks

    I tried this

    <?php echo file_exists ('file.txt') ? nl2br (htmlentities (file_get_contents ('file.txt'))) : '&nbsp;' ?>
    and it does what i need. Show text files in a cell

    I took MstrBob advice and search for something else

    thanks

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    If it works, great.
    I don't have access to any PHP functions so I would not be able to solve the problem via this method.
    I was going by the original question of:
    can i do it?? can i do it with javascript?

  6. #6
    Join Date
    Jun 2006
    Posts
    23
    yes, you are right that was my question. I appreciate it :P

    thanks

  7. #7
    Join Date
    Jul 2003
    Location
    New York City
    Posts
    2,771
    Quote Originally Posted by JMRKER
    Depending upon what you want to display in the '.txt' file, you could read information in as a javascript string with a few modifications and change the extension to '.js'
    Well, actually, I was thinking that a simply XMLHttpRequest call would be simplest. You would simply gather it with the XMLHttpRequest.responseText property, instead of the usualy responseXML property call. But, it would be simpler to simply make your page a PHP page. Then you would insert the PHP call into your table cell


    PHP Code:
    <td><?php echo (file_exists('file.txt')?file_get_contents('file.txt'):'File unavailable';?></td>
    There really shouldn't be a need for those other two functions. nl2br() and htmlentities() are normally used to sanitize input, you probably won't need them. Just make your page a .php page, and put the PHP call directly where you want the file contents to be.

    Unless I'm misunderstanding you...

  8. #8
    Join Date
    Feb 2006
    Location
    Where I live, people get shot. I need to move.
    Posts
    634
    Quote Originally Posted by MstrBob
    ... You never want to rely on javascript, since not everyone has it. ...
    If you have a standard install of Windows, you will have javascript as part of the install. What you mean is that NOT everyone has it ENABLED in their browser.
    If life gives you a hard knock once in a while, your lucky. All I keep getting is a savage beating... everyday!
    AJAX! - Javascript Sha1 & MD5 - ASCII tables - Zend DevZone - My Space
    Stop Badware - Create "TEXT FILE" in Javascript - . - wikipedia on PHP -

  9. #9
    Join Date
    Jul 2003
    Location
    New York City
    Posts
    2,771
    Quote Originally Posted by netbuddy
    If you have a standard install of Windows, you will have javascript as part of the install. What you mean is that NOT everyone has it ENABLED in their browser.
    No, that's not what I mean. True, every window user who gets a default install of windows on an unsecured network has access to a graphical browser with Javascript (IE). The same applies for Mac (Safari) and a lot of Desktop Distros of Linux (Firefox, Opera, Konqueror, ect.)

    However, if you are on a secure network, they often disable javascript. If you are blind and using an audio browser, then no javascript. If you are a search engine spider, you don't support javascript. If you are using a PDA or other portable device (phone), not all the browsers support Javascript. If you are running an operating system without a GUI, you will be running a textual browser (such as Lynx) and won't have javascript. If you are a webserver requesting a page for some web app, you won't have javascript. If you are security or privacy minded, you might have javascript turned off.

    That's a non-inclusive list. Don't fall into the dangerous trap of thinking that all web traffic is for graphical desktop browsers such as IE or Firefox.

  10. #10
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    A lot of people using web readers have Javascript disabled or their reader doesn't support Javascript. Also people who listened to Microsoft about how to plug most of the outstanding security holes in IE by turning off ActiveX will also have turned off Javascript to get rid of all of the stupid ActiveX disabled popups.

    Statistics show that an average of 10% of visitors to web sites don't have Javascript enabled. Whether this figure includes Search Engine spiders or not I don't know but if it does then that still leaves about 7% of real people visiting without Javascript.
    Stephen

  11. #11
    Join Date
    Feb 2006
    Location
    Where I live, people get shot. I need to move.
    Posts
    634
    Quote Originally Posted by MstrBob
    No, that's not what I mean. True, every window user who gets a default install of windows on an unsecured network has access to a graphical browser with Javascript (IE). The same applies for Mac (Safari) and a lot of Desktop Distros of Linux (Firefox, Opera, Konqueror, ect.)

    However, if you are on a secure network, they often disable javascript. If you are blind and using an audio browser, then no javascript. If you are a search engine spider, you don't support javascript. If you are using a PDA or other portable device (phone), not all the browsers support Javascript. If you are running an operating system without a GUI, you will be running a textual browser (such as Lynx) and won't have javascript. If you are a webserver requesting a page for some web app, you won't have javascript. If you are security or privacy minded, you might have javascript turned off.

    That's a non-inclusive list. Don't fall into the dangerous trap of thinking that all web traffic is for graphical desktop browsers such as IE or Firefox.

    EVEN if javascript is disabled in the web browser, it is still available to the operating system, network admins use scripting for logins on terminals to set up individual configs and access and retrieve data from the remote machine.

    If your Blind, you wont have javascript disabled, the net admin or person responsible for that persons login would ensure that they have adequate access to system resources.

    If your a web server, you have access to Server-side javascript...

    Running Linux? Whatever floats your boat man.

    Not all browsers support javascript... if they dont, what are they doing in the market place? If you go to a hardware store and ask for a power drill and find out that the inner components are optional, would you want to buy it??? Same applys to a browser without adequate support for the end user to acomplish their goals.

    In reality, theirs more threat from other scripting languages that can run in the browser that have far more potential for destruction than javascript and quite why people dont just exercise some basic internet security, they wouldnt all be living in a world of paranoia.
    If life gives you a hard knock once in a while, your lucky. All I keep getting is a savage beating... everyday!
    AJAX! - Javascript Sha1 & MD5 - ASCII tables - Zend DevZone - My Space
    Stop Badware - Create "TEXT FILE" in Javascript - . - wikipedia on PHP -

  12. #12
    Join Date
    Jul 2003
    Location
    New York City
    Posts
    2,771
    Quote Originally Posted by netbuddy
    EVEN if javascript is disabled in the web browser, it is still available to the operating system, network admins use scripting for logins on terminals to set up individual configs and access and retrieve data from the remote machine.
    Maybe in some select enviroments. Some systems may use Javascript for scripting at a terminal, but honestly there are much better scripting langauges for this. Shell, Perl, and the like are normally used. But it doesn't matter, because even if you had an operating system that had a Javascript interpreter built in, it wouldn't be available to a webpage unless the browser used it internally to interpret the javascript.

    Quote Originally Posted by netbuddy
    If your Blind, you wont have javascript disabled, the net admin or person responsible for that persons login would ensure that they have adequate access to system resources.
    Yes, an admin in a network would make sure that a blind person had the neccessary system resources, such as an audio browser. Not every blind person is on an administered network, blind people have home PC's, too. Plus, regardless of what the net admin is doing, they still browse the web, and have browsers that don't interpret Javascript (Or else have a very limited Javascript implementation). This is the nature of things, audio browsers are a very different enviroment.

    Quote Originally Posted by netbuddy
    If your a web server, you have access to Server-side javascript...
    Server-side Javascript is a server-side scripting language. Instead of using something such as PHP or Python on the server-side, you can use Javascript to script pages. The server does NOT interpret the javascript on page requests from other servers.

    Quote Originally Posted by netbuddy
    Running Linux? Whatever floats your boat man.
    Yes, actually, I run Linux and Windows. KDE, in my opinion, is a much nicer GUI than Windows, I'm far more productive in it. I usually run Firefox, but sometimes use Konqueror. Both, of course, support Javascript.

    Of course, not every computer on the web is a desktop (or laptop) PC. There are numerous embedded devices. Linux, as you know, is merely a kernel. So I could very easily run it on, say, a kiosk, a toaster, or a dedicated terminal in which running a GUI would be impossible or a waste of resources. Same goes for Unix, BSD, or any number of other operating systems running without a GUI.

    Quote Originally Posted by netbuddy
    Not all browsers support javascript... if they dont, what are they doing in the market place? If you go to a hardware store and ask for a power drill and find out that the inner components are optional, would you want to buy it??? Same applys to a browser without adequate support for the end user to acomplish their goals.
    Your analogy is innacurate. All that's required from a browser is the ability to connect to webservers and download files from them. So if browsers were drills, then they would all work. Now you could equate having javascript to having a lot more torque. So maybe for you, user A, you are in construction and so a drill without a lot of torque seems pointless. But for User B, who only needs a drill for very small hand-crafts, all that torque is unneccessary and a waste. To each his own. But why reject User B because of his choice of drill?

    Look, like it or not, there are many users without Javascript. If nothing else, the fact that search engine spiders can't interpret javascript is enough for me NOT to rely on Javascript to deliver content. You are also locking out a large number of users. And of course, if you were contracted to work on a government website in the US, it would be illegal, since the website would not be available to disabled persons.

    It's important to remember that javascript is a very useful tool. You can use it to do all sorts of things, just make sure the page does not rely on javascript. Or if it does, make sure there's a non-javscript equivalent available.

    There are exceptions, of course. If you are working on a Web 2.0 app or some such thing, feel free to rely on Javascript. It's a web application, it's not meant for everyone. I wouldn't have a commercial website that relied on a web app for content, though, because that would be asinine.

    Like any good tool, you should use Javascript in moderation. Right tool for the right job.

  13. #13
    Join Date
    Jan 2006
    Posts
    78
    var answer = boat.indexOf('float') ? 'Go sailing m8.' : 'Whatever.';
    Reverse engineer this ****er!

  14. #14
    Join Date
    Feb 2006
    Location
    Where I live, people get shot. I need to move.
    Posts
    634
    Do you really believe that someone with a text based terminal would be surfing the net? Most text only terminals dont have a screen of any use, generally monotone in colour and are specifically used in an environment where access to the web is not needed via conventional means but are networked over a LAN or WAN.

    I could see an AS400 being used as a corporate server for web delivery, bit of an over kill mind you but I certainly wouldnt expect someone to be using one to surf the net or at home (unless you had bags of money.)

    Like you pointed out, each to their own.
    If life gives you a hard knock once in a while, your lucky. All I keep getting is a savage beating... everyday!
    AJAX! - Javascript Sha1 & MD5 - ASCII tables - Zend DevZone - My Space
    Stop Badware - Create "TEXT FILE" in Javascript - . - wikipedia on PHP -

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles