Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Pull <link rel="image_src" from another URL to use as current page's

    I am trying to extract the <link rel="image_src" information from a page and use it on the current one. Currently I am using:

    Note: The source url is defined via a variable on my url minus http:// (example currentpage.php?url=www.extractinfo.com)


    Code:
    function getImgSrc(){
        $varurlstr = 'http://' . $_GET["url"]; 
        $str = file_get_contents($varurlstr);
        if(strlen($str)>0){
            preg_match('/<link.+"image_src".+href="([^"]+)"/U', $str, $ilsource);
            return $ilsource;
        }
    }

    and

    Code:
    <link rel="image_src" href="<?php echo getImgSrc();?>" />
    However that returns as:
    <link rel="image_src" href="Array" />


    Am I missing something? Knowing my luck it's something simple O

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    $ilsource IS AN ARRAY!
    Why not do a foreach on it in the getImgSrc() function as see what you got.
    Evolution - The non-random survival of random variants.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    $ilsource[0] will contain the entire text that is matched, $ilsource[1] will contain the first match, $ilsource[2] the second, etc.

    So you want to return $ilsource[1] if you know there will only be one match.

  • Users who have thanked Keleth for this post:

    sunfighter (08-26-2013)

  • #4
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    $ilsource[0] will contain the entire text that is matched, $ilsource[1] will contain the first match, $ilsource[2] the second, etc.

    So you want to return $ilsource[1] if you know there will only be one match.
    I read these two posts and the first thing that hits the back of my head is ....."DUUUHHHHH! Stupid!" lol

    Thanks guys. I had an idiot moment. I am so badly lost today due to lack of sleep these past 4 days.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •