PHP/HTML/htmlentities — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
Содержание
Checking for magic quotes
<?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: <strong>$search</strong>.";
}
}
?>
Encoding HTML entities in a string
$comments = htmlentities($_POST["comments"]);
print $comments.
Escaping HTML
<?php
print "The comment was: ";
print htmlentities($_POST["comment"]);
?>
Generating XML from an array
<?
$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>";
?>
htmlentities() function converts all characters into their equivalent HTML entities.
The syntax is: string htmlentities (string string)
<?
$user_input = "costs < $42.25.";
$converted_input = htmlentities($user_input);
print $converted_input;
?>
htmlentities.php
<?php
$advertisement = ""Cafè Française";
echo htmlentities($advertisement);
?>