Reply to Re: Retrieving data from remote file - question from complete newbie

Your name:

Reply:


Posted by Erwin Moller on 11/15/41 11:23

Timothy Murphy wrote:

> Erwin Moller wrote:
>
>>> My question is: how can I download a timetable
>>> from a remote URL
>>> <http://www.irishrail.ie/your_journey/timetables.asp>
>>> after giving a number of values like txtFromStation=Salthill .
>
>> If you just need to open a file or URL, you can use fopen:
>> Read more here:
>> http://nl3.php.net/manual/en/function.fopen.php
>
>> If you need to POST data (like it came from a form) you might have a look
>> at curl.
>> Read more here:
>> http://nl3.php.net/manual/en/ref.curl.php
>
>> But in general: If this is you first day on PHP, you better spend your
>> time in a good book first.
>> Try to do all you learn in the book first, THEN start on a real project.
>> In my experience: When learning something new, spend some real time in a
>> good book (or site) first.
>> In the end you will finish faster than learning it the hard way, that is
>> trail and error.
>
> Thanks for your URLs, which I am looking at now.
>
> But as to your last remarks,
> I glanced (30 seconds) at a couple of PHP books,
> and it seemed to me that they were entirely devoted to
> the topic of using PHP in a web _server_.

The most coosy and relaxed place to be for PHP. :-)
But of course you can also run it from a commandline.
I think I even saw some guys who where using PHP to interact with TCL to
make GUI's. :-)
It can all be done.

>
> I'm not interested in this as I don't run a web server.
> I'm only concerned with the question if one can use PHP
> to query a remote server,
> and if so exactly how does one go about it?

Yes you can.
try fopen.
I am NOT sure CURL works without a servercontext.
You'll have to figure that one out yourself. (Maybe it is on the page I
recommented on php.net)

>
> I gather I could get the information I want (a timetable)
> from the server in question by pointing the browser at the URL,
> with the specific variable values at the end
> as part of the URL.

Yes, that is generally reffered to as GET.
(Or querystring in VB-world)

>
> I guess my question is, can one query a form on a remote server
> in the same way by using a PHP script?

yes.
One can fetch a document on a remote server.
eg:
$handle = fopen("http://www.example.com/bla.asp?id=343", "r");
which returns a handle you can use to read the content.

or even with 'file':
$lines = file('http://www.example.com/bla.php?testing=328746');

Once again: I am UNSURE if these function work outside a webserver.

> If so, how exactly does one do it?
>
> One problem I have with the PHP tutorials I've glanced at
> is that while they have reams about PHP syntax
> they very rarely tell you exactly what command
> you are supposed to use to invoke their scripts.
> It is as though this information was given in section -1
> before the tutorial started.

That is probably because 99,99% of the users of PHP USE it in a webserver as
scriptinglanguage, and not commandline, like you want.
So that is what the books focus on.

In your case:
Just try to make a simple PHP-program that uses file() and try to fetch the
documents you want.
Just let it spit out the document to STOUT.

If you get that working, you can build from there.

Is that answering your question?
(not sure.)

Regards,
Erwin

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация