例えば:
$str="<script>alert('hello');</script>";
echo を使用して印刷すると、ブラウザに警告ウィンドウが表示されます。
<script>alert('hello');</script>
この場合、生の文字列を出力するにはどうすればよいですか?
例えば:
$str="<script>alert('hello');</script>";
echo を使用して印刷すると、ブラウザに警告ウィンドウが表示されます。
<script>alert('hello');</script>
この場合、生の文字列を出力するにはどうすればよいですか?
単語を入れたいかどうかによりますscript
。はいの場合は、
これを使うべきです。
echo htmlspecialchars($str);
http://php.net/manual/en/function.htmlspecialchars.phpを参照してください。
http://php.net/manual/en/function.strip-tags.phpを使用しない場合strip_tags
使用できますhtmlspecialchars
$str = htmlspecialchars( "<script>alert('hello');</script>" )
ドキュメント: http://php.net/manual/en/function.htmlspecialchars.php