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', '\\\\hostname\\xyz\\Informatiker.mp4"> bs bs', '&#92;&#92;hostname&#92;xyz&#92;Informatiker.mp4"> BS2', '\\\\">2x Bw slash', 'file://">file', 'relative/path">relative/path' ); $replacements = array('/((?:href|src) *= *[\'"](?!(http|ftp|mailto|file|javascript|#|[a-z]+:|\\\\|\/\/)))(\/?)/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.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<<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="\\hostname\xyz\Informatiker.mp4"> bs bs</a> => <a href="\\hostname\xyz\Informatiker.mp4"> bs bs</a></pre> <<pre><a href="&#92;&#92;hostname&#92;xyz&#92;Informatiker.mp4"> BS2</a> => <a href="http://www.server.tld/ABSOLUTE/PATH/&#92;&#92;hostname&#92;xyz&#92;Informatiker.mp4"> BS2</a></pre> <<pre><a href="\\">2x Bw slash</a> => <a href="\\">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:
278.8 ms | 407 KiB | 398 Q