Skip to content

Commit 1cea8bc

Browse files
committed
Add some security function
1 parent c28a482 commit 1cea8bc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

htmlspecialchars.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
// htmlspecialchars
3+
4+
/*
5+
Convert special characters to HTML entities
6+
e.g. :
7+
"<" convert to "&lt;"
8+
">" convert to "&gt;"
9+
...
10+
*/
11+
$str = "The word <b>text</b> is bold";
12+
echo htmlspecialchars($str);
13+
// HTML output will be "The word &lt;b&gt;text&lt;/&gt; is bold"
14+
15+
$str = "My name is 'Ali'";
16+
echo htmlspecialchars($str);
17+
18+
$str = "What is decrement & increment ?";
19+
echo htmlspecialchars($str);

stripslashes.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
// stripslashes
3+
4+
/*
5+
# Remove backslashes
6+
This function can be use for clean data received
7+
from user.
8+
*/
9+
$str = "Hello \ my name \ is Ali";
10+
var_dump(stripslashes($str));
11+
12+
// and can be use for ignore escape sequences
13+
$str = "Wellcome \n This is world";
14+
var_dump(stripslashes($str));

0 commit comments

Comments
 (0)