Php implements the html tag filtering method in form submission. form tag _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags form post
Php implements the method of filtering html tags in form submission. Php implements the method of filtering html tags in form submission. This document describes how php implements the method of filtering html tags in form submission. Share it with you for your reference. Implement php to filter html tags in form submission.

This example describes how to filter html tags in form submission in php. Share it with you for your reference. The specific implementation method is as follows:

Sometimes the simple comment function we make will find that many html tags are submitted, which may cause some external connections to the page, let's take a look at the html tag method used to filter form submissions in php.

Some post links submitted by robots in recent comments are all spam comments. To reduce the unnecessary link content, you can use php to delete the html tag submitted by form POST, so that the information submitted by the machine will not get the expected result. In addition, it can reduce penalties from seo/seo.html "target =" _ blank "> search engines.

Remove it here
Tag:

In some cases, we need to remove
Tag. you can use the str_replace function.

The code is as follows:

// Retrieve the br Mark
$ Str = str_replace ("
"," ", $ Str );


Remove html tags:
You can use the strip_tags function.

The code is as follows:

$ Str = strip_tags ($ str );


Encapsulated into a function:

The code is as follows:

<? Php
Function removehtml ($ str ){
$ Str = str_replace ("
"," ", $ Str );
Return strip_tags ($ str );
}
?>

I hope this article will help you with php programming.


Php code for filtering redundant html tags

Php code for filtering redundant html tags!
Nction filterhtml ($ str)
{
$ Str = stripslashes ($ str );

$ Str = preg_replace ("// \ s +/", '', $ str); // filter excess carriage returns
$ Str = preg_replace ("/[] +/si", '', $ str); // filter _ (" "with spaces)

$ Str = preg_replace ("/\! --.*? -->/Si ",'', $ str); // comment
$ Str = preg_replace ("/(\!. *?)> /Si ",'', $ str); // filter DOCTYPE
$ Str = preg_replace ("/(\/? Html. *?)> /Si ",'', $ str); // filter html tags
$ Str = preg_replace ("/(\/? Head. *?)> /Si ",'', $ str); // filter head tags
$ Str = preg_replace ("/(\/? Meta. *?)> /Si ",'', $ str); // filter meta Tags
$ Str = preg_replace ("/(\/? Body. *?)> /Si ",'', $ str); // filter the body tag
$ Str = preg_replace ("/(\/? Link. *?)> /Si ",'', $ str); // filter link tags
$ Str = preg_replace ("/(\/? Form. *?)> /Si ",'', $ str); // filter form labels
$ Str = preg_replace ("/cookie/si", "COOKIE", $ str); // filter COOKIE tags

$ Str = preg_replace ("/(applet. *?)> (.*?) (\/Applet. *?)> /Si ",'', $ str); // filter the applet tag
$ Str = preg_replace ("/(\/? Applet. *?)> /Si ",'', $ str); // filter the applet tag

$ Str = preg_replace ("/(style. *?)> (.*?) (\/Styl ...... remaining full text>

Filter html tags using php

You can use the strip_tags function to remove html tags, including removing font tags.
For example, you can check the usage of this function in the official php Manual.
$ Text ='

Test paragraph. </p> Other text </a> ';
Echo strip_tags ($ text );
Echo "\ n ";
Echo strip_tags ($ text ,'

'); // Allow

, Label
?>
Output result:
Test paragraph. Other text

Test paragraph. </p> Other text </a>
I hope it will be helpful to you.

Examples in this article describes how php filters html tags in form submission. Share it with you for your reference. Specific implementation...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.