954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ AND PHP mixing?

Hi guys. I have a php script that reads some values off a website and prints to a file every second.. The thing is, the script is always ran in my browser and I don't like that.

I want to write a c++ program that can run that script within it and write the data to a file.

If that is not possible, can I use C++ to read the contents off of a website, given the link?

Example: The php script is given the link to the website and given the elements the data is contained in. It reads that into an array and prints the data to a file.. If the data is between two div tags with a unique ID, the php file will look for the div tags with that ID and print it to an array.. Can I do this in C++??

TLDR: Can C++ Run PHP scripts/files? Can C++ Read data from a website without opening my browser?

triumphost
Posting Whiz
390 posts since Oct 2009
Reputation Points: 57
Solved Threads: 36
 

You could do it in either language.
If you don't like it running in the browser, you make a command-line version.

########################################################################
# Read content from a web page
$fileInFile=fopen("http://server.ext/Resources/SmallTextFile.txt", "rb");
while(!feof($fileInFile))
{
   $strData = fgets($fileInFile);
   printf($strData);
}
fclose($fileInFile);
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

You could do it in either language. If you don't like it running in the browser, you make a command-line version.

########################################################################
# Read content from a web page
$fileInFile=fopen("http://server.ext/Resources/SmallTextFile.txt", "rb");
while(!feof($fileInFile))
{
   $strData = fgets($fileInFile);
   printf($strData);
}
fclose($fileInFile);


How would I do it in C++?

triumphost
Posting Whiz
390 posts since Oct 2009
Reputation Points: 57
Solved Threads: 36
 
How would I do it in C++?

you can't do that with just pure C++. You will have to use external libraries like ncurses

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 
you can't do that with just pure C++.


It would be difficult in "pure" C++.
I personnaly would use C++/CLI with the WebClient class and call the OpenRead() method that opens a Stream. I would feed that into a StreamReader and treat it like a file.

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You