PHP function code for filtering html tags_PHP tutorial

WBOY
Release: 2016-07-20 11:01:43
Original
904 people have browsed it

PHP function code for filtering HTML tags. This article provides four function codes for filtering HTML tags using PHP. Method one is the simplest, using PHP's own function strip_tags to filter all HTML tags. Method two uses regular expressions to filter HTML. Tags, the third method is to clear the user-defined function of HTML tags, and then filter based on the ascii encoding value to determine whether it is a letter. ​

php tutorial function code for filtering html tags
This article provides four function codes that use PHP to filter HTML tags. The first method is the simplest to use PHP's own function strip_tags to filter all HTML tags. The second method uses regular expressions to filter HTML tags. The third method is to clear HTML. The user-defined function of the label determines whether it is a letter based on the ascii encoding value and then filters it.
*/
//The most direct way to filter html

strip_tags();

//Method 2 uses regular filtering
function _filter( $string ) {
Return str_replace(array("n","rn","r",' '),array('
','
','
',' '),strip_tags($string,'

PHP function code for filtering html tags_PHP tutorial'));
}

//Regular 2

preg_replace('/(
){1,}/is','
', $str);


//Regular Three

function delhtml($str){ //Clear html tag
$st=-1; //Start
$et=-1; //End
$stmp=array();
$stmp[]=" ";
$len=strlen($str);
for($i=0;$i<$len;$i++){
$ss=substr($str,$i,1);
If(ord($ss)==60){ //ord("<")==60
$st=$i;
}
If(ord($ss)==62){ //ord(">")==62
$et=$i;
If($st!=-1){
$stmp[]=substr($str,$st,$et-$st+1);
}
}
}
$str=str_replace($stmp,"",$str);
return $str;
}
//

$str='


 www.bkjia.com />

';
$reg = '/(|)|<.+?>/i';
echo preg_replace($reg,'$1',$str);
*>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445430.htmlTechArticlephp function code for filtering html tags. This article provides four function codes for filtering html tags using php. Method one is the best. Simply use PHP's built-in function strip_tags to filter all html tags...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!