PHP - String manipulation remove spcial characters and replace spaces

后端 未结 5 1409
余生分开走
余生分开走 2020-12-15 14:57

I am getting strings from a database and then using the strings to build a URL. My issue is, some of the strings will have characters like < > & { } * general specia

5条回答
  •  悲哀的现实
    2020-12-15 15:34

    str_replace(' ','-',$string);
    

    alphanumeric:

    $output = preg_replace("/[^A-Za-z0-9]/","",$input); 
    

    if you want to keep the characters:

     htmlspecialchars($string);
    

提交回复
热议问题