@ 2013-07-01T12:44:39Z <?php
//$pattern = '/(?:src|href)\=(?:\\\'|")([^\\\'"]+)(?:\\\'|")/';
$pattern = '/background\w+\:\w+url\w+\(\w+(?:\\\'|")([^\\\'"]+)(?:\\\'|")\w+\)/'
$source = <<<SRC
<a href="http://www.sape.ru">some text</a>
<img src='logo.jpg' alt=''></a>
<img src='../../logo.jpg' alt=''></a>
<img src='/path/to/file' alt=''></a>
<img src='./path/to/file' alt=''></a>
<img src='www.sape.ru/path/to/file' alt=''></a>
<img src='path/to/file.png' alt=''></a>
<span style="background:url('path/to/url.jpg')">
SRC;
$baseUrl = 'www.sape.ru';
$callback = function($matches) use ($baseUrl) {
$srcTag = $matches[0];
$url = $matches[1];
$search = array(
$baseUrl,
'http://' . $baseUrl,
'https://' . $baseUrl,
'http://',
'https://',
'../',
'./',
'//',
'/'
);
$baseUrlReplace = $baseUrl . '/';
$resultUrl = $url;
$count = 0;
foreach($search as $s) {
$count = 0;
$resultUrl = preg_replace('/^' . preg_quote($s, '/') . '/', $baseUrlReplace, $url, 1, $count);
if ($count == 1) {
break;
}
}
if (!$count) {
$resultUrl = $baseUrlReplace . $url;
}
$search = array(
'../',
'./'
);
foreach($search as $s) {
$resultUrl = preg_replace('/' . preg_quote($s, '/') . '/', '', $resultUrl);
}
$resultUrl = preg_replace('/\/{2,}/', '/', $resultUrl);
$resultUrl = 'http://' . $resultUrl;
var_dump($resultUrl);
return str_replace($url, $resultUrl, $srcTag);
};
$source = preg_replace_callback($pattern, $callback, $source);
var_dump($source);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.16 0.010 0.042 12.37 5.4.15 0.010 0.043 12.37 5.4.14 0.010 0.044 12.06 5.4.13 0.009 0.043 12.04 5.4.12 0.008 0.042 12.01 5.4.11 0.012 0.045 12.00 5.4.10 0.010 0.040 12.00 5.4.9 0.008 0.040 12.00 5.4.8 0.010 0.038 12.00 5.4.7 0.009 0.039 12.00 5.4.6 0.010 0.038 12.00 5.4.5 0.010 0.038 12.00 5.4.4 0.011 0.038 11.99 5.4.3 0.016 0.056 11.98 5.4.2 0.010 0.045 11.98 5.4.1 0.008 0.044 11.99 5.4.0 0.008 0.044 11.48 5.3.26 0.011 0.043 12.72 5.3.25 0.019 0.057 12.72 5.3.24 0.012 0.042 12.72 5.3.23 0.011 0.041 12.71 5.3.22 0.012 0.047 12.68 5.3.21 0.011 0.046 12.68 5.3.20 0.015 0.046 12.68 5.3.19 0.012 0.043 12.68 5.3.18 0.011 0.041 12.67 5.3.17 0.014 0.050 12.67 5.3.16 0.013 0.051 12.67 5.3.15 0.012 0.048 12.67 5.3.14 0.012 0.055 12.66 5.3.13 0.014 0.051 12.66 5.3.12 0.014 0.060 12.66 5.3.11 0.013 0.047 12.66 5.3.10 0.010 0.047 12.12 5.3.9 0.013 0.047 12.08 5.3.8 0.012 0.046 12.08 5.3.7 0.012 0.042 12.08 5.3.6 0.012 0.044 12.06 5.3.5 0.012 0.039 12.00 5.3.4 0.012 0.042 12.00 5.3.3 0.012 0.042 11.95 5.3.2 0.012 0.037 11.73 5.3.1 0.013 0.047 11.69 5.3.0 0.009 0.040 11.68
preferences:dark mode live preview
138.97 ms | 1394 KiB | 7 Q