-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
TextParsing.php
38 lines (34 loc) · 985 Bytes
/
TextParsing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/SForum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/SForum/blob/master/LICENSE
*/
namespace App\Plugins\Core\src\Lib;
use App\Plugins\User\src\Models\User;
use Hyperf\Stringable\Str;
class TextParsing
{
public function keywords($keywords): string
{
return <<<HTML
<a href="/keywords/{$keywords}.html">#{$keywords}</a>
HTML;
}
public function at($username): string
{
$username = Str::after($username, '@');
$username = trim($username);
$username = strip_tags($username);
if (User::query()->where('username', $username)->exists()) {
$uid = User::query()->where('username', $username)->first()->id;
return <<<HTML
<a href="/users/{$uid}.html">@{$username}</a>
HTML;
}
return '@' . $username;
}
}