-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmlspecialchars.php
46 lines (46 loc) · 1.36 KB
/
htmlspecialchars.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
<meta charset='utf-8'>
<title>HTML特殊文字変換</title>
<script type='text/javascript'>
// クリア処理
function c(){
document.forms['demo'].input_data.value = "";
document.forms['demo'].output_data.value = "";
}
// 選択処理
function s(){
document.forms['demo'].output_data.focus();
document.forms['demo'].output_data.select();
}
</script>
</head>
<body>
<form name='demo' action='htmlspecialchars.php' method='post'>
<textarea name='input_data' cols='100' rows='10' wrap='soft'>
<?php
/* 送信内容の表示 */
if($_POST){
print htmlspecialchars($_POST['input_data'], ENT_QUOTES, 'UTF8');
}
?>
</textarea>
<br/>
<input type='submit' value='変換' />
<input type='button' value='クリア' onclick='c()'><br/>
<textarea name='output_data' cols='100' rows='10' wrap='soft' readonly>
<?php
/* 特殊文字変換結果の表示 */
if($_POST){
// デザイン部 (background, border, padding, height, overflow)
print "<pre style="background-color:#FFFFF0; border:1px dotted #000000; padding:5px; height: 200px; overflow:auto;"><code>";
// 入力文字列変換部
print str_replace('&', '&', htmlspecialchars($_POST['input_data'], ENT_QUOTES, 'UTF8'));
print "</code></pre>";
}
?>
</textarea><br/>
<input type='button' value='選択' onclick='s()' />
</form>
</body>
</html>