Files
DevandCursor 60daff2365 搭建轻舟一期门户、后台和统一登录。
让分类、会员和示例工具共用同一账号,本地即可跑通登录与授权。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-09 16:46:35 +08:00

23 lines
722 B
PHP

<?php
namespace App\Support;
class HtmlSanitizer
{
public static function clean(?string $html): string
{
$html = strip_tags((string) $html, '<p><br><strong><em><ul><ol><li><a><h2><h3><code>');
$html = preg_replace('/\son\w+\s*=\s*("[^"]*"|\'[^\']*\'|[^\s>]+)/i', '', $html) ?? '';
$html = preg_replace_callback('/<a\b([^>]*)>/i', function (array $matches) {
$attrs = $matches[1];
if (! preg_match('/href\s*=\s*("|\')(https?:\/\/[^"\']+)\1/i', $attrs, $href)) {
return '<a>';
}
return '<a href="'.htmlspecialchars($href[2], ENT_QUOTES).'" rel="noopener noreferrer">';
}, $html) ?? '';
return $html;
}
}