Strip out HTML and Special Characters

后端 未结 9 1310
别跟我提以往
别跟我提以往 2020-12-07 12:39

I\'d like to use any php function or whatever so that i can remove any HTML code and special characters and gives me only alpha-numeric output

$des = "He         


        
9条回答
  •  Happy的楠姐
    2020-12-07 13:04

    Here's a function I've been using that I've put together from various threads around the net that removes everything, all tags and leaves you with a perfect phrase. Does anyone know how to modify this script to allow periods (.) ? In other words, leave everything 'as is' but leave the periods alone or other punctuation like and ! or a comma? let me know.

    function stripAlpha( $item )
    
    {
    
        $search     = array( 
             '@]*?>.*?@si'   // Strip out javascript 
            ,'@]*?>.*?@siU'    // Strip style tags properly 
            ,'@<[\/\!]*?[^<>]*?>@si'            // Strip out HTML tags
            ,'@@'         // Strip multi-line comments including CDATA
            ,'/\s{2,}/'
            ,'/(\s){2,}/'
    
        );
    
        $pattern    = array(
    
             '#[^a-zA-Z ]#'                     // Non alpha characters
            ,'/\s+/'                            // More than one whitespace
    
        );
    
        $replace    = array(
             ''
            ,' '
    
        );
    
        $item = preg_replace( $search, '', html_entity_decode( $item ) );
        $item = trim( preg_replace( $pattern, $replace, strip_tags( $item ) ) );
        return $item;
    
    }
    

提交回复
热议问题