Input value 따옴표 이스케이프

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:34 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
Input value 큰따옴표 이스케이프

1 PHP[ | ]

영어라면 htmlentities()로도 가능하나, 한글/특수문자까지 처리가능한 htmlspecialchars() 사용 권장
<?php
$roman = <<<EOT
'War' and "Peace"
EOT;
 
$roman1 = addslashes($roman);
$roman2 = htmlentities($roman);
$roman3 = htmlspecialchars($roman);
 
echo "0. [$roman]<br>";
echo "1. <input type='text' value=\"$roman1\"><br>"; // \'War\' and \
echo "2. <input type='text' value=\"$roman2\"><br>"; // 'War' and "Peace"
echo "3. <input type='text' value=\"$roman3\"><br>"; // 'War' and "Peace"
 
$hangul = <<<EOT
'전쟁'과 "평화"
EOT;
 
$hangul1 = addslashes($hangul);
$hangul2 = htmlentities($hangul);
$hangul3 = htmlspecialchars($hangul);
 
echo "0. [$hangul]<br>";
echo "1. <input type='text' value=\"$hangul1\"><br>"; // \'전쟁\'과 \
echo "2. <input type='text' value=\"$hangul2\"><br>"; // 'ì �ì��'ê³¼ "í��í��"
echo "3. <input type='text' value=\"$hangul3\"><br>"; // '전쟁'과 "평화"

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}