Php code to get webpage contents from another webpage...

Discussion in 'PHP' started by bikram_068, Mar 18, 2010.

  1. #1
    Hi
    I want to get all the webpage contents in my website from another url.
    I have already tried get_file_contents() but there was the relative url problem.
    Also file open and some other functions were also have similar problem.
    Could any one give me how I can get all the webpage contents to my website with php code?
    Or how can I get rid of relative url not shown with get_file_contenst()?
    Thanks.
    H.
     
    bikram_068, Mar 18, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what do you mean by relative url problem?
     
    krsix, Mar 18, 2010 IP
  3. bikram_068

    bikram_068 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    In the remote url...there is given url of image as (../images/tree.jpg)..then using file_get_contents will parse it as "www.mysite.com/images/tree.jpg" instead of "www.remoteurl/images/tree.jpg".That donot show the images when clicked.
    That is what I tried to say.
    But absolute url starting from "http://www.remoteurl.../.../" are alright there.
    Could you have any idea?
    thanks.
     
    bikram_068, Mar 18, 2010 IP
  4. featuredoffers.info

    featuredoffers.info Member

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    what exactly happened when you tried using get_file_contents( ) ?
     
    featuredoffers.info, Mar 18, 2010 IP
  5. bikram_068

    bikram_068 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When I used the get_file_contents(), it worked well and gave the webpage as it is.But when I clicked to all the images, they were linked to my browser as "www.MYSITE.com/images" (suppose that MYSITE is my domain)...but it should be www.remotesite.com/images.
    The problem was , in the remote site the images was given relative url as (../images/1.jpg)...which has to be as remotesite/images/1.jpg inside my site.But inside my site,using file_get_contents() it is pointing to my site for the images to show which is wrong.
    I have get all the web contents using iframe but I want it to be with php.
    Do you have any idea?
    Thanks in advance
     
    bikram_068, Mar 18, 2010 IP
  6. featuredoffers.info

    featuredoffers.info Member

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    Thanks man, I will get back to you in sometime. pls check for my reply later
     
    featuredoffers.info, Mar 18, 2010 IP
  7. bikram_068

    bikram_068 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok i m eagerly waiting your reply..thanks.
     
    bikram_068, Mar 18, 2010 IP
  8. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #8
    You would need to use
    preg_replace
    PHP:
    to point the image urls to the external website
     
    MyVodaFone, Mar 18, 2010 IP
  9. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #9
    maybe the site have blocked access (hotlinking)
     
    guardian999, Mar 18, 2010 IP
  10. bikram_068

    bikram_068 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Could you please give an example of preg_replace with file_get_contents()?
    thanks...
     
    bikram_068, Mar 18, 2010 IP
  11. SolomonZhang

    SolomonZhang Peon

    Messages:
    523
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Just use
    $result=str_replace("../","http://www.domain.com",$TheTextSourceToReplace);
    Code (markup):
    It will work nicely for any relative links into the sub level. Basically you only have one "../"

    However, if you try to fetch pages that has a link to parent level pages it would be a different case (e.g. if you have "../../../")

    More info on php.net http://php.net/manual/en/function.str-replace.php

    p.s. if this helps you, please don't forget to add my reputation :D
     
    SolomonZhang, Mar 18, 2010 IP
  12. bikram_068

    bikram_068 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Actually my parent level is "../../".Can you please give me the full code(also comments..) with file_get_contents()?
    Thanks.
     
    bikram_068, Mar 19, 2010 IP