<?php
$pre ="<a href=\"";
$post= "</a>";
$in = array('http://">http',
'ftp://">ftp',
'mailto://">mailto',
'#">HASH',
'//">2xfw slash',
'\\\\">2x Bw slash',
'file://">file',
'relative/path">relative/path'
);
$replacements = array('/((?:href|src) *= *[\'"](?!(http|ftp|mailto|file|javascript|#|[a-z]+:|'. preg_quote('yyyy\\\\',"/"). '|\/\/)))(\/?)/i'
=> "$1" . "http://www.server.tld/ABSOLUTE/PATH/"
);
foreach($in as $test) {
echo "\n". '<<pre>';
$r = $pre . $test . $post;
echo "$r \t\t=>\t\t" . preg_replace(array_keys($replacements), $replacements, $r);
echo '</pre>';
}
preferences:
45.29 ms | 402 KiB | 5 Q