Help me to understand how to fetch this text file

OK here is the url

very simple text file. I need to come up with php code that goes to this url and logs this text every hour.
Text need to be inserted into mysql database , top data and time on text file and bottom part into another

how can i do it please help

This is how you can get the two lines in two variables. Do you know how to do an SQL insert or do you need help with that as well?


<? $lines = file(''); $top_line = $lines[0]; $bottom_line = $lines[1]; ?>


oh and to run this script every hour you will need a ‘Cron Job’, I cant describe how to do this very well so I will point you towards…

Unless you are guaranteed at least one visiter an hour, then you can include this script on your index.php page and put an if statement in to check if it has been an hour since the script was last run, and if so then run it…

Yes i need the script on putting this into mysql database. Thanks in advance,

I know the cron job part. I just need to put this into mysql database

ok say the table is called “tbl_example” and it has columns “top_line” and “bottom_line”


<? $lines = file(''); $top_line = $lines[0]; $bottom_line = $lines[1]; INSERT INTO tbl_example (`top_line`, `bottom_line`) VALUES("$top_line","$bottom_line"); ?>


should be what you need

sorry mate, missed the mysql_query part of course…
mysql_query(“INSERT INTO tbl_example (top_line, bottom_line) VALUES(’$top_line’,’$bottom_line’)”);

How about mysql database login and stuff? I’m planning to put this code on my hosting and also setup cron job. I try running first code and nothing happened. Can you put complete code here. I’m very new sorry


$dbhost = “…”; //the name of your host, for example “
$dbuser = “…”; //your database username
$dbpass = “…”; //your database password
$dbname = “…”; //the name of the database you are accessing

//this connects to mysql
$dbconnection=mysql_connect($dbhost, $dbuser, $dbpass);

//if it cannot make a connection then the mysql error is shown
if (!$dbconnection) {
die('Could not connect: ’ . mysql_error());

//this selects the correct database
$db_selected=mysql_select_db($dbname, $dbconnection);

$lines = file(‘’);

$top_line = $lines[0];
$bottom_line = $lines[1];

mysql_query(“INSERT INTO tbl_example (top_line, bottom_line) VALUES(’$top_line’,’$bottom_line’)”);


Didn’t work. I created databases and stuff but nothing in the database

Oh it did add only top part till 2010

Hey maas do you mind adding me to your MSN. Mine is b e s t b u y 4 u s “@” h o t m a i l . c o m

sorry mate I dont use MSN. I have just set up a database with those headings and run the script myself, and for me it works perfectly. Check your two columns are VARCHAR and to be sure put size as 400, double check that the names of the columns are the same in your script.

my database columns in tbl_example
top_line || VARCHAR(400)
bottom_line || VARCHAR(400)

I did

CREATE TABLE aerofox_metar.tbl_example (
top_line VARCHAR( 400 ) NOT NULL ,
bottom_line VARCHAR( 400 ) NOT NULL

I’ll be testing soon.
We’ll see what will happen

It works! Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service