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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading from a file

Status
Not open for further replies.

jayne1

Technical User
Feb 5, 2002
7
GB
Hi everyone,

Here's my problem.....I am would like to open a file for read using fopen (the text file contains info within <td> </td> tags). How can i open the file and then print the contents to the web browser.......does that make sense??

if not please let me know!!
your help is greatly appreciated.
 
You can use <td> etc for seperation of data, howevere more often the | is used. When you read the file, check when you arive at the <td> fill a new variable with the data until you reach the </td>.
for finding <td> and </td> use ereg strstr.

Is that the answer you are looking for? mcvdmvs
&quot;It never hurts to help&quot; -- Eek the Cat
 
if the data in the text file is formated in the way you want it to display, you can use the include directive
e.g.
file.php:
------
Code:
<?
echo &quot;<html><body><table><tr>&quot;;
include('data.txt');
echo &quot;</tr></table></body></html>&quot;;
?>

data.txt
-----
Code:
<td>your data</td>
<td>your data</td>
<td>your data</td>
 
THANKS FOR THE ADVICE GUYS, BUT...........

I can't use 'include' tag because the data is not in complete html format. I have tried using the substr function to print the required line but with NO luck! - here's my code:

$fp=fopen(&quot;results/file&quot;, &quot;r&quot;);
$matchdate = substr(&quot;matchdate&quot;, 16 ,6);
print (&quot;Date played: ${matchdate}&quot;);fclose($fp);

PLEASE HELP!!!
xxx
Jayne

 
The include file doesn't have to be in complete html. If you look closer to piti's response you are wrapping the proper html around the include file.

All that you're include file needs is to be properly formatted for the information that it contains. In other words, is the information in the include file proper delimited with the <tr> and <td> tags? If you so then you are good to go using piti's response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top