3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getDescriptionAttribute($string) { $pattern = "~(https?://\S+)|([^\s@]+@[^\s@]+)|(\+\d+)~"; return preg_replace_callback($pattern, function($matches) { $template = '<a href="%1$s%2$s" rel="noopener nofollow" target="_blank">%2$s</a>'; if ($matches[1] !== "") return sprintf($template, "", $matches[1]); if ($matches[2] !== "") return sprintf($template, "mailto:", $matches[2]); if ($matches[3] !== "") return sprintf($template, "tel:", $matches[3]); }, $string); } $str = 'http://google.com tester@gmail.com +1818254545400'; echo getDescriptionAttribute($str);
Output for 7.3.13 - 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.28, 8.4.1 - 8.4.14, 8.5.0
<a href="http://google.com" rel="noopener nofollow" target="_blank">http://google.com</a> <a href="mailto:tester@gmail.com" rel="noopener nofollow" target="_blank">tester@gmail.com</a> <a href="tel:+1818254545400" rel="noopener nofollow" target="_blank">+1818254545400</a>
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
193.86 ms | 407 KiB | 5 Q