The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

C program - Getting data from a php script

Hi

I have a small program, written in C. At one point this program needs to get a filename. A php script must return the filename. It could be a php page on a webserver or php command script, what matters is that I must get the info from php. I´m not sure what the best way so here are 2 questions:

1. Is there any easy way to get html pages in C, something included in the win api or a common library. All I would need is to get http://foo.com/e.php and read the body.

2. Can i somehow get the string I need from a command line php script? Somehow call it and then read it's stdout or something like that?

Any hints, or suggestions for other ways are welcome :)

thanks.
Not a C programmer...
Monday, January 23, 2006
 
 
"A php script must return the filename. It could be a php page on a webserver or php command script, what matters is that I must get the info from php."

I'm dying to know why.  No particular reason, I'm just interested to know.
Deane Send private email
Monday, January 23, 2006
 
 
As you suggested, you can call a command-line PHP script, have it send its response to stdout, and read that from the C program.
JW
Monday, January 23, 2006
 
 
1. Yes, you could use WinInet functions. I expect you can find a sample on MSDN or codeproject.com or somewhere

2. Yes, you could (for example IIRC - it's a long time since I did this, and never specifically for kicking off PHP) use CreateProcess to kick off the PHP prog and make its output be readable by the C. Or you could probably also simply pipe the PHP prog's output into the C's stdin
Let's play Sudoku
Monday, January 23, 2006
 
 
you could execute a simple program that knows http ( like wget ) and parse the results
B Send private email
Monday, January 23, 2006
 
 
Like so?  mycprogram reads filename from stdin:

php getfilename.php | mycprogram
Michael Johnson Send private email
Monday, January 23, 2006
 
 
oops:
(quiet mode)
php -q my_php_prog.php | mycprog

if the page is remote.. why not build a local php file that can do the file(url) for you.
Michael Johnson Send private email
Monday, January 23, 2006
 
 
"if the page is remote.. why not build a local php file that can do the file(url) for you."

Or this:

curl url | mycprogram


If reading from stdin isn't going to work, then surely Windows must have some equivalent of popen().
clcr
Monday, January 23, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz