Strip out HTML and Special Characters

后端 未结 9 1286
别跟我提以往
别跟我提以往 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条回答
  • 2020-12-07 13:24

    In a more detailed manner from Above example, Considering below is your string:

    $string = '<div>This..</div> <a>is<a/> <strong>hello</strong> <i>world</i> ! هذا هو مرحبا العالم! !@#$%^&&**(*)<>?:";p[]"/.,\|`~1@#$%^&^&*(()908978867564564534423412313`1`` "Arabic Text نص عربي test 123 و,.m,............ ~~~ ٍ،]ٍْ}~ِ]ٍ}"; ';
    

    Code:

    echo preg_replace('/[^A-Za-z0-9 !@#$%^&*().]/u','', strip_tags($string));
    

    Allows: English letters (Capital and small), 0 to 9 and characters !@#$%^&*().

    Removes: All html tags, and special characters other than above

    0 讨论(0)
  • 2020-12-07 13:24

    to allow periods and any other character just add them like so:

    change: '#[^a-zA-Z ]#' to:'#[^a-zA-Z .()!]#'

    0 讨论(0)
  • 2020-12-07 13:24

    Remove all special character don't give space write in single line

    trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', 
    urldecode(html_entity_decode(strip_tags($string))))));
    
    0 讨论(0)
提交回复
热议问题