PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I need get contents of a website, and then use it on my site. Its just the ranks of players and their army sizes. I tried using the following but it doesn’t work. I get this error:
Warning: file_get_contents(http%3A%2F%2Fwww.kingsofchaos.com%2Fbattlefield.php%3Fstart%3D0): failed to open stream: No such file or directory in /home/nokiddin/public_html/test.php on line 11
Sorry about not searching, I was in a hurry, also havent try seen this topic around. Anway, So I can display the page. But I need to get speific text from it. How should I go about doing so?
The Manual wrote:file_get_contents -- Reads entire file into a string
Identical to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.
If you're writing a tutorial I'd strongly advise to write about fsockopen() over file_get_contents() because some websites reject requests if the User-Agent header is not sent (you can either do this with fsockopen() or using the cURL library).
I have recently completed a project for a client which take a hell of a lot of useful data from any given website (in a similar fashion to a search engine) and I was forced to take the fsockopen() route after noticing numerous rejections with file_get_contents().
If you need a basic example of using fsockopen() to send a HTTP 1.0 or 1.1 request there's some examples in the manual.