0

I'm using this code to prepend the URL variable inside the src tag for images. Now I want an regex code that makes it possible to search for <link> tags and add the URL variable inside the link tags href attribute. This is the code I have for the images; might help explain things:

function imgprepend_proxy($matches2) {
   $url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}";
    $prepend2 = $matches2[2] ? $matches2[2] : $url;
    $prepend2 = $prepend2 . '/';

    return $matches2[1] . $prepend2 . $matches2[3];
}



$new_content = preg_replace_callback(
    '|(href=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i',
    'prepend_proxy',
    preg_replace_callback(
        '|(src=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i',
        'imgprepend_proxy',
        $content
    )
);
TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 3
    "This code i have ... might give u hints." Ooh, I love a good puzzle. – Ryan Florence Aug 11 '09 at 13:15
  • http://stackoverflow.com/questions/1254890/pregreplacecallback-do-twice/1254923#1254923 - This is where the code was from. Looks like a bit of a homework assignment type of task. – Mez Aug 11 '09 at 14:02
  • hihi, i just want some help. That's all. –  Aug 11 '09 at 14:07

1 Answers1

0

Well, it seems that your current code should prepend the URL to every src attribute (by the imgprepend_proxy function) and every href attribute (by prepend_proxy), regardless of HTML element (tag). However, there's no prepend_proxy function in the code you posted. Perhaps it doesn't exist at all?

Ignas R
  • 3,314
  • 2
  • 23
  • 27
  • http://stackoverflow.com/questions/1254890/pregreplacecallback-do-twice/1254923#1254923 – Mez Aug 11 '09 at 14:01
  • Okay... Now I'm really confused. The author got this question answered yesterday, so why is (s)he asking it again? – Ignas R Aug 11 '09 at 14:12