3v4l.org

run code in 300+ PHP versions simultaneously
<?php function modifyText($text) { $url = '~https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}(?:\/\S*(?<!\.))?~'; $string= preg_replace($url, '<a href="$0" target="_blank">$0</a>', $text); return $string; } echo modifyText("Example text... https://example.com/site. More text here... https://example.com/site");
Output for 7.1.25 - 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
Example text... <a href="https://example.com/site" target="_blank">https://example.com/site</a>. More text here... <a href="https://example.com/site" target="_blank">https://example.com/site</a>

preferences:
154.2 ms | 408 KiB | 5 Q