我想允許<img> <strong> <p>站點用戶可以使用相同的 HTML 標簽,但是如何檢查這些標簽的濫用情況,例如未關閉的標簽<p>可以通過關閉</p>網站主題來匹配并使頁面損壞?另外,我會縮短長帖子以顯示在索引頁面上,這也可能導致標簽損壞。Laravel 有一個csrf-token防止跨站點腳本的標簽,但似乎沒有檢查我所說的內容。
1 回答

慕尼黑8549860
TA貢獻1818條經驗 獲得超11個贊
我不知道這個問題的 laravelish 方式,但您可以使用正則表達式編寫自己的驗證函數。p這是標簽的演示:
// Html code here
$html = 'here';
// Strip newlines so we won't need multilines modifiers
$html = str_replace("\r\n", "", $html);
// Strip correct <p>...</p> tags and their content from html data
$html = preg_replace("@<p>.*?</p>@", "", $html);
// Check if any <p> tag remains in data. If so, it means a tag has been unenclosed/enclosed incorrectly
$s[0] = strpos($html, '<p>');
$s[1] = strpos($html, '</p>');
if($s[0] !== false || $s[1] !== false)
echo "Syntax error in HTML code";
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消