I have a page setup on my website so i can fetch it and use it on multiple websites. This is the code that i tried using and it doesnt seem to work. <table> <tr> <td> <?=file_get_contents ('http://www.domain.com/index2.php');?> </td> </tr> </table> Is there a different way of fetching php content?
To fetch the content of other page 1. You should have the file name with the extension of .php (example.php) 2. Use the following code To fetch the content of other page 1. You should have the file name with the extension of .php (example.php) 2. Use the following code <table> <tr> <td> <?php include ('http://www.domain.com/index2.php'); ?> </td> </tr> </table> Code (markup):
alfa_375 you can't include a php from a different domain, the code will have already been parsed by the other server, and the include() function is expecting valid PHP code, not html. Normally <?=file_get_contents ('http://www.domain.com/index2.php');?> would work. But in cases where your server doesn't support that function, or its not allowed, there's the curl method, for example this function that acts like file_get_contents(). function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } PHP: As far as your question goes " fetching php content", keep in mind that if you try to grab a php file from another webserver over http protocol, the php code will become executed on that server and what you grab will only be the resulting html output.
By the way... did you know you had a space in between file_get_contents and the first ( ... that would be a problem if you actually had a space there (as its a function call, not a if () etc).
you should have to use the curl library to fetch the contents of other site and regular expressions to extract only some part of site....
CURL() is best option to fetch data from other site. You need to enable curl on your server. You can also display content of other site by using your own code which will parse page and will display only specific contents on your website.
i agree yes use curl is the better way to fetch website, but some times file get contents is more better than curl. i like to use file_get_contents .
most of the time on shared hosting all the funtions like file_get_contents, fopen(url) are disabled due to high probability of abuse