htmlentities [PHP 4, PHP 5]
Convert all applicable characters to HTML entities.
string htmlentities [ string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get["default_charset"] [, bool $double_encode = true ]]] ]
This function is identical to htmlspecialchars[] in all ways, except with htmlentities[], all characters which have HTML character entity equivalents are translated into these entities.
If you're wanting to decode instead [the reverse] you can use html_entity_decode[].
HttpUtility.HtmlEncode Method [String] .NET Framework 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Converts a string to an HTML-encoded string.
public static string HtmlEncode[ string s ]
HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as < and > for HTTP transmission.
next → ← prev
PHP htmlentities[] function is string function, which is used to convert character to HTML entities.
Syntax:
String | Specify the string to convert. | required |
flags | Specify how to manage quotes, invalid encoding. | optional |
Character | Specify the character set | optional |
Double_encode | Specify a Boolean value. | optional |
Example 1
Output:
Go to javatpoint.com
Example 2
Output:
Hello PHP : 'E=MC�' Hello PHP : 'E=MC�' Hello PHP : 'E=
Next TopicPHP String
← prev next →
Feedback
- Send your Feedback to [email protected]
What is the easiest way to Html encode in PHP?
Somnath Muluk
52.5k34 gold badges216 silver badges224 bronze badges
asked Dec 9, 2009 at 13:13
1
By encode, do you mean: Convert all applicable characters to HTML entities?
htmlspecialchars
or htmlentities
You can also use strip_tags if you want to remove all HTML tags :
strip_tags
Note: this will NOT stop all XSS attacks
answered Dec 9, 2009 at 13:16
VallièresVallières
1,39912 silver badges17 bronze badges
4
Encode.php
Encode HTML CODE
htmlencodeoutput.php