Strip php variable, replace white spaces with dashes

前端 未结 3 2064
梦谈多话
梦谈多话 2020-12-04 07:21

How can I convert a PHP variable from \"My company & My Name\" to \"my-company-my-name\"?

I need to make it all lowercase, remove all special characters and repl

3条回答
  •  执笔经年
    2020-12-04 07:45

    Yop, and if you want to handle any special characters you'll need to declare them in the pattern, otherwise they may get flushed out. You may do it that way:

    strtolower(preg_replace('/-+/', '-', preg_replace('/[^\wáéíóú]/', '-', $string)));
    

提交回复
热议问题