add tag parse on messages
This commit is contained in:
parent
6277142a8d
commit
10eba95e06
1 changed files with 6 additions and 1 deletions
|
|
@ -9,11 +9,16 @@ class Utils
|
|||
$text = e($text);
|
||||
// url replace and email replace
|
||||
$text = preg_replace_callback(
|
||||
'/([^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/',
|
||||
'/(?P<email>[^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?P<user>@\w*)|(?P<url>(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*))/',
|
||||
function ($matches) {
|
||||
$match = collect($matches)->first() ?? '';
|
||||
if (filter_var($match, FILTER_VALIDATE_EMAIL)) {
|
||||
return strlen($match) ? "<a href=\"mailto:$match\">$match</a>" : $match;
|
||||
} elseif (isset($matches['user']) and strlen($matches['user'])) {
|
||||
return sprintf(
|
||||
'<span class="text-primary fw-bold font-weight-bold">%s</span>',
|
||||
$matches['user']
|
||||
);
|
||||
} else {
|
||||
$url = $match;
|
||||
if (\strpos($url, 'http') === false and \strpos($url, 'https') === false) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue