read and display content from URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    read and display content from URL

    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
  • Nert
    New Member
    • Nov 2006
    • 64

    #2
    Originally posted by exoskeleton
    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 :



    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
    Hi exoskeleton..,

    Uhmmn i'm kinda confuse with your problem.., but try the include function in PHP, it might help you to solve your problem.

    for example:
    you want to display the output of the page http://www.sample.com/a.php to the page http://www.xample.com/b.php

    from the coding of the page b.php you just put something like this;
    [PHP]<?php
    // include('path of a certain page you want to include');
    include('a.php' );
    ?>[/PHP]

    hope that helps you.


    --nert (^_^)

    Comment

    • exoskeleton
      New Member
      • Sep 2006
      • 104

      #3
      Originally posted by Nert
      Hi exoskeleton..,

      Uhmmn i'm kinda confuse with your problem.., but try the include function in PHP, it might help you to solve your problem.

      for example:
      you want to display the output of the page http://www.sample.com/a.php to the page http://www.xample.com/b.php

      from the coding of the page b.php you just put something like this;
      [PHP]<?php
      // include('path of a certain page you want to include');
      include('a.php' );
      ?>[/PHP]

      hope that helps you.


      --nert (^_^)
      thank you sir...but not that kind! it still displays the <HTML>....blah. .blah...

      i only want to display the output...the "HELLO WORLD" only

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        If you 'include' a file within php and that file has no php braces then the file is output as a HTML file. You should not see the tags.

        Comment

        • bucabay
          New Member
          • Apr 2007
          • 18

          #5
          Originally posted by exoskeleton
          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]

          Comment

          • exoskeleton
            New Member
            • Sep 2006
            • 104

            #6
            Originally posted by bucabay
            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]

            Thank you sir...i'll try you code!

            Comment

            • pentrac
              New Member
              • Apr 2007
              • 2

              #7
              Well...I am not sure whether the problem I am facing is the same as this. I am trying to read the content of a HTML file, then save the details into database.

              Lets say this is the HTML output:

              Name : pentrac
              Email : pentrac@yahoo.c om

              I am trying to save 'pentrac' and 'pentrac@yahoo. com' into a table in mysql. I don't really know if we can do that with PHP. Well...I hope some of you can help me with this...

              Thanks in advance... :)

              Comment

              Working...