Strip out HTML and Special Characters

后端 未结 9 1307
别跟我提以往
别跟我提以往 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:13

    Strip out tags, leave only alphanumeric characters and space:

    $clear = preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags($des));
    

    Edit: all credit to DaveRandom for the perfect solution...

    $clear = preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags(html_entity_decode($des)));
    

提交回复
热议问题