Thread: Read PHP from C

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    Read PHP from C

    Hello Gurus,

    I would like to know how we can read a PHP webpage using C.

    For example lets say we have a php page which has

    Name Vinod Krishnan
    Age 24

    How can these values be retrieved and stored in a variable in C.

    I tried to get this info all over the web and I couldn't get it. Could some one please help me on this?

    Thank you very much in advance.
    Thanks
    Vinod

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    As far as I know PHP is a server side scripting language, which means that you don't actually read the PHP but the effects of the PHP code when issuing a request to the server. From that point of view I think you should read on how socket programming works in C to get started on this.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Do it all yourself using the lowest level API available
    Beej's Guide to Network Programming
    +
    http://www.ietf.org/rfc/rfc2616.txt

    Use a library which does a lot of the low level stuff for you.
    cURL and libcurl

    The 'PHP' is irrelevant, how the stream of HTTP gets generated doesn't matter.
    All you see is the stream of bytes, and that is what you have to deal with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03:32 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. I am lost on how to read from file and output to file?
    By vicvic2477 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 11:52 AM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM