


The difference between php using htmlspecialchars() and strip_tags functions to filter HTML tags
Original address: http://www.manongjc.com/article/1103.html
First let’s take a look at the usage examples of htmlspecialchars function and strip_tags function:
<?php $str="<a href='http://www.manongjc.com'>码农教程'\"</a>"; echo htmlspecialchars($str); echo "<br/><br/>"; echo strip_tags($str); ?>
The browser outputs the following results:
Coder Tutorial' "
Coder Tutorial'"
View the page source code, the results are as follows:
<a href='http://www.manongjc.com'>码农教程'"</a><br/><br/>码农教程'"
From the results, we can see that the difference between htmlspecialchars() and strip_tags is as follows:
Difference 1:
strip_tags function is used to remove HTML tags, while htmlspecialchars does not remove html tags, but only converts tags into HTML instances, so the biggest difference between the two is that one is to delete HTML tags, and the other is to convert html tags into other characters.
Difference 2:
If the tag in the string that needs to be removed from the HTML tag is originally wrong, for example, the greater than symbol is missing, an error will be returned when using the strip_tags function, but no error will appear with htmlspecialchars, still and then converted to HTML entities.
Difference 3:
When preventing XSS attacks, it is generally recommended to use the htmlspecialchars function, because although strip_tags can delete HTML tags, it will not delete " or '. Therefore, even if you use strip_tags, you still need to use the htmlspecialchars function To filter out " or '
" in form submission or user message board, if you want the original data output with the browser, then please use the htmlspecialchars function, do not use the strip_tags function.
For information about htmlspecialchars() and strip_tags functions, please refer to:
http://www.manongjc.com/article/1213.html
http://www.manongjc.com/article/1099.html
http://www.manongjc.com/article/795.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.