Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saroarhossain57/0204eb4ae50b2e9b63635241efa899cc to your computer and use it in GitHub Desktop.
Save saroarhossain57/0204eb4ae50b2e9b63635241efa899cc to your computer and use it in GitHub Desktop.
<?php
$input = '<button name="submit">Delere</button>@copy;';
echo htmlentities($input);
echo '<br>';
?>
<?php
//encode a html code to string for all the charecter
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
?>
<?php
//encode a html code to string for some spacial charecter
echo '<h1>htmlspecialchars function</h1><br><br>';
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;
?>
<?php
//remove all html tags from a sting.
echo '<h1>strip_tags() function</h1><br><br>';
echo strip_tags("<del>Hello</del> <b><i>world!</i></b>","<i><del>");
?>
<?php
//filter all the sql injection in html form for inserting data.
//mysqli_real_escape_string($db_con, $sring);
?>
<?php
echo '<h1>filter_var() function</h1><br><br>';
//filter php function
$email = '[email protected]';
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'The email is valid!';
}
else{
echo 'The email you have entered is not valid';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment