I have a lot of strings of special characters.
I want to replace all special characters with chara开发者_StackOverflow社区cter "-"
The characters do not need to be replaced as "-" are "A-Za-z0-9"
try this :
preg_replace("/[^A-Za-z0-9-]/", "-", $yourString);
Resources :
- php.net - preg_replace()
Pretty straight forward.
$text = preg_replace('~[^0-9a-z]~i', '-', $text);
Extra Information
See Regular-Expressions.info for further information.
The ^ inside the Character Class [] at the start basically says, "Match any character except the ones following it". 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论