Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_replace_回调-执行两次_Php_Regex_Preg Replace Callback - Fatal编程技术网

Php preg_replace_回调-执行两次

Php preg_replace_回调-执行两次,php,regex,preg-replace-callback,Php,Regex,Preg Replace Callback,哟,我正试着让这个脚本工作,但它不工作。我如何做两次,preg_replace_回调使用两个不同的函数。谢谢 function prepend_proxy($matches) { $url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}"; $prepend = $matches[2] ? $matches[2] : $url; $prepend = '

哟,我正试着让这个脚本工作,但它不工作。我如何做两次,preg_replace_回调使用两个不同的函数。谢谢

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