Replace all kind of dashes

ⅰ亾dé卋堺 提交于 2019-12-01 23:41:29

问题


I have a excel document which I import in MySQL using a library.

But some of the texts in the document contain dashes which I though I have replaced, but apparently not all of them. -, , - <-all of these are different.

Is there any way I could replace all kind of dahes with this one -

The main problem is that I dont know all of the dashes that exist in computers.


回答1:


Just use regex with unicode modifier u and a character class:

$output = preg_replace('#\p{Pd}#u', '-', $input);

From the manual : Pd Dash punctuation

Online demo




回答2:


How about:

$string = str_replace(array('-','–','-','—', ...), '-', $string);

Use the above code and see if it works. If you're still seeing some dashes not being replaced, you can just add them into the array, and it'll work.



来源:https://stackoverflow.com/questions/18234545/replace-all-kind-of-dashes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!