hi guyz..please help me dear experts. my boss wants to display something from other sites in our page. can someone who have a kind hearted to help me deal with this? please...
i used fopen() but it displays the code of the site...i only want to display the real output. this means what you see exactly on the IE or other explorers.
is this possible? for example i have :
http://www.sample.com/a.php
and the output is "hello world" then i want that output display in other page like http://www.xample.com/b.php
please help...me...
TIA
If you post a bit of your code it would be easier to figure out the problem.
What you're trying to do I believe is "screen scrape" the contents of another webpage and display it on your webpage?
If you do something like:
[PHP]echo file_get_conten ts("http://www.sample.com/a.php");[/PHP]
You will echo the whole HTML of the page http://www.sample.com/a.php from your php script.
IF you do:
include("http://www.sample.com/a.php");
You will get the exact same thing. This is because you are including a file from HTTP and the include() function will first register a wrapper for the HTTP stream and "download" the page "http://www.sample.com/a.php" just as if you made a HTTP connection. So you will receive the resulting HTML after the server at http://www.sample.com/ parses "a.php" and not the PHP code.
This is different from including a file in your own directory, as you will be including the raw PHP code.
Usually if you're going to screen scrape a webpage then you only want certain parts of the HTML. You can get this data using regular expressions or you could parse the HTML into PHP Objects using a XML parsing standard such as DOM or SAX etc. (These are built into most PHP versions)
Example of using regex to get the HTML in between <body> and </body> in an HTML page:
[PHP]
$cotnent = file_get_conten ts("http://www.sample.com/a.php");
preg_match("/<body(.*?)>(.+? )<\/body>/s", $content, $matches);
echo $matches[2];
[/PHP]