If i have a textfile called text.txt, inside the textfile at column 2 line 6 there is one word "help" how do i read that word and print it out with php/html?
Asked
Active
Viewed 1,125 times
0
-
You can't with pure HTML, you would need some scripting language. – jtheman Apr 18 '13 at 13:46
-
If the textfile is on the server, you'll have to use a server-side language to read it and then write to your page. HTML is only for markup and can't access files in any way. – brbcoding Apr 18 '13 at 13:46
-
@brbcoding It can be done client side with js, see here: http://stackoverflow.com/questions/4533018/how-to-read-a-text-file-from-server-using-javascript – jtheman Apr 18 '13 at 13:47
-
@jtheman that's true, AJAX would be one way to handle it. – brbcoding Apr 18 '13 at 13:51
2 Answers
2
With HTML it is impossible. You need to use PHP or other language.
Using PHP
<?php
$arr = file ("text.txt");
substr($arr[5],2,4);
?>
or if you want exact word to be found.
<?php
$arr = file ("text.txt");
preg_match('/help/', $arr[5], $matches);
print_r($matches);
?>
http://php.net/manual/en/function.substr.php

Robert
- 19,800
- 5
- 55
- 85
0
Need to use php like here: http://www.html.net/tutorials/php/lesson15.php Just insert php code inside your html page. Use array and string operations to do what you need.

Halabella
- 59
- 3
- 7