# 功能小记：将空格转为-中划线

**URL:** <https://www.shiqidu.com/t/topic/649>\
**Category:** 开发调优\
**Tags:** 互联网\
**Created:** [2019 年9 月 28 日 05:03 UTC](https://www.shiqidu.com/t/topic/649 "2019-09-28T05:03:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![dajiang](https://www.shiqidu.com/user_avatar/www.shiqidu.com/dajiang/32/468_2.png) [@dajiang](https://www.shiqidu.com/u/dajiang)\
发布日期： [2019 年9 月 28 日 05:03 UTC](https://www.shiqidu.com/t/topic/649/1 "2019-09-28T05:03:51Z")

</div>

需求：根据用户输入的字符如果有空格则根据空格将字符串用-串联起来  
preg\_replace(“/(\s+)/u”,“-”,$string);
