问题
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