views:

393

answers:

1

Hi! I'm using this code to prepend the url variabel inside the src tag for images. Now i would want an regex code that makes it possible to search for tags and add the url variabel inside the link tags href attribute. This code i have for the images, it might give u hints.

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
    )
);
A: 

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
http://stackoverflow.com/questions/1254890/pregreplacecallback-do-twice/1254923#1254923
Mez
Okay... Now I'm really confused. The author got this question answered yesterday, so why is (s)he asking it again?
Ignas R