3v4l.org

run code in 300+ PHP versions simultaneously
<?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>'; }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
<<pre><a href="http://">http</a> => <a href="http://">http</a></pre> <<pre><a href="ftp://">ftp</a> => <a href="ftp://">ftp</a></pre> <<pre><a href="mailto://">mailto</a> => <a href="mailto://">mailto</a></pre> <<pre><a href="#">HASH</a> => <a href="#">HASH</a></pre> <<pre><a href="//">2xfw slash</a> => <a href="//">2xfw slash</a></pre> <<pre><a href="\\">2x Bw slash</a> => <a href="http://www.server.tld/ABSOLUTE/PATH/\\">2x Bw slash</a></pre> <<pre><a href="file://">file</a> => <a href="file://">file</a></pre> <<pre><a href="relative/path">relative/path</a> => <a href="http://www.server.tld/ABSOLUTE/PATH/relative/path">relative/path</a></pre>

preferences:
243.25 ms | 407 KiB | 307 Q