PHP/HTML/htmlentities
Содержание
Checking for magic quotes
<source lang="html4strict">
<?php if (is_null($_GET["search"])) {
echo "<form method="".htmlentities($_SERVER["PHP_SELF"])."" method="GET">"; echo " <label>"; echo " Search:"; echo " <input type="text" name="search" id="search" />"; echo " </label>"; echo " <input type="submit" value="Go!" />"; echo "</form>"; } else { $search = $_GET["search"]; if (!get_magic_quotes_gpc( )) { $search = htmlentities($search); } if ($search != NULL ){ echo "The search string is: $search."; }
} ?>
</source>
Encoding HTML entities in a string
<source lang="html4strict">
$comments = htmlentities($_POST["comments"]); print $comments.
</source>
Escaping HTML
<source lang="html4strict">
<?php print "The comment was: "; print htmlentities($_POST["comment"]); ?>
</source>
Generating XML from an array
<source lang="html4strict">
<? $channel = array("title" => "A",
"link" => "http://example.ru/", "description" => "test");
print "<channel>\n"; foreach ($channel as $element => $content) {
print " <$element>"; print htmlentities($content); print "</$element>\n";
} print "</channel>"; ?>
</source>
htmlentities() function converts all characters into their equivalent HTML entities.
<source lang="html4strict">
The syntax is: string htmlentities (string string) <? $user_input = "costs < $42.25."; $converted_input = htmlentities($user_input); print $converted_input; ?>
</source>
htmlentities.php
<source lang="html4strict">
<?php
$advertisement = ""Cafè Française"; echo htmlentities($advertisement);
?>
</source>