<?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);
You have javascript disabled. You will not be able to edit any code.