seo.html_encode.how_desc
- seo.html_encode.how_step1
- seo.html_encode.how_step2
- seo.html_encode.how_step3
- seo.html_encode.how_step4
seo.html_encode.how_example
HTML'de güvenli gösterim için özel karakterleri HTML varlıklarına dönüştürün.
HTML varlık kodlama, özel karakterleri tarayıcıların güvenle gösterebileceği HTML varlıklarına (metin gösterimleri) dönüştürür. Bu, HTML'de özel anlama sahip karakterlerin kod olarak yorumlanmasını önler.
seo.html_encode.how_desc
seo.html_encode.how_example
HTML varlık kodlama, HTML'nin kendisiyle birlikte evrildi. HTML5 spesifikasyonu, adlandırılmış karakter referanslarını (< > & gibi) ve sayısal referansları (< veya <) tanımlar. Varlık kodlama, tarayıcıların özel karakterleri HTML işaretlemesi olarak yorumlamasını önler, bu da onu güvenlik ve içerik gösterimi için vazgeçilmez kılar.
HTML encoding prevents XSS attacks by converting special characters to safe entities. Always encode user input before displaying it on web pages. Learn about encoding security
Çoğu dil XSS saldırılarını önlemek için HTML varlık kodlama sağlar. İşte örnekler:
// htmlspecialchars() - standard encoding (recommended)
$encoded = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
// Encodes: < > & " '
// htmlentities() - encodes ALL special characters
$encoded = htmlentities($data, ENT_QUOTES, 'UTF-8');
// Encodes: < > & " ' plus accented characters, etc.
// For attribute values (always use ENT_QUOTES)
echo '<div title="' . htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8') . '">';
// Laravel Blade templates (auto-encoding)
// {{ $userInput }} - automatically HTML encoded
// Browser: textContent (automatic encoding - recommended)
element.textContent = userInput; // Safe, auto-encoded
// Creating elements safely
const div = document.createElement('div');
div.textContent = userInput; // Safe
// Manual encoding function
function htmlEncode(str) {
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
}
// Library: DOMPurify (for sanitizing HTML)
const clean = DOMPurify.sanitize(dirtyHTML);
import html
# html.escape() - standard encoding
encoded = html.escape(userInput)
# Encodes: < > &
# With quote encoding
encoded = html.escape(userInput, quote=True)
# Encodes: < > & " '
# Django templates (auto-encoding)
# {{ user_input }} - automatically HTML encoded
# {{ user_input|safe }} - NO encoding (dangerous!)
# Jinja2 templates (auto-encoding)
# {{ user_input }} - automatically encoded
import "html"
// html.EscapeString() - standard encoding
encoded := html.EscapeString(userInput)
// Encodes: < > & " '
// In Go templates (html/template package auto-encodes)
tmpl := template.Must(template.New("page").Parse("<p>{{.}}</p>"))
tmpl.Execute(w, userInput) // Auto-encoded safely
// Apache Commons Text (recommended)
import org.apache.commons.text.StringEscapeUtils;
String encoded = StringEscapeUtils.escapeHtml4(userInput);
// Encodes: < > & " '
// OWASP Java Encoder (most secure)
import org.owasp.encoder.Encode;
String encoded = Encode.forHtml(userInput);
// Spring MVC (auto-encoding in JSP)
// <c:out value="${userInput}"/> - auto-encoded
require 'cgi'
# CGI.escapeHTML() - standard encoding
encoded = CGI.escapeHTML(user_input)
# Encodes: < > & " '
# Rails (ERB templates auto-encode)
# <%= user_input %> - automatically HTML encoded
# <%== user_input %> - NO encoding (dangerous!)
# html_safe marker (tells Rails string is safe)
# safe_html.html_safe - skips encoding
using System.Web;
using System.Net;
// HttpUtility.HtmlEncode() - standard encoding
string encoded = HttpUtility.HtmlEncode(userInput);
// Encodes: < > & " '
// WebUtility (no System.Web dependency)
string encoded = WebUtility.HtmlEncode(userInput);
// Razor views (auto-encoding)
// @Model.UserInput - automatically HTML encoded
// @Html.Raw(Model.UserInput) - NO encoding (dangerous!)
Need to decode HTML entities? Use our HTML Entity Decoder to convert < > & back to characters.
Encoding data for URLs? Try our URL Encoder to make text URL-safe.
Encoding binary data? Use our Base64 Encoder for binary-to-text conversion.