2009-08-10 5 views
0

Yo, ich versuche, dieses Skript funktioniert, aber es funktioniert nicht. Wie mache ich es zweimal, die Preg_replace_callback mit zwei verschiedenen Funktionen. Vielen Dank!preg_replace_callback - do double

function prepend_proxy($matches) { 
    $url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}"; 
    $prepend = $matches[2] ? $matches[2] : $url; 
    $prepend = 'proxy2.php?url='. $prepend .'/'; 

    return $matches[1] . $prepend . $matches[3]; 
} 

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', 
    '|(src=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i', 
    'imgprepend_proxy', 
    $content 
); 

Antwort

0
$new_content = preg_replace_callback(
    '|(href=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i', 
    'prepend_proxy', 
    preg_replace_callback(
     '|(src=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i', 
     'imgprepend_proxy', 
     $content 
    ) 
); 
+0

Vielen Dank! Das hat funktioniert! –