PHP Replace EM Dash REGEX -


i trying replace character http://www.fileformat.info/info/unicode/char/2014/index.htm regular dash , have yet cant seem work?

$dataold = "9am – 5pm"; // ms word doc  $data = mb_ereg_replace("[\xe2 \x80 \x94]", " - ", $dataold);  print_r($data); 

why bother octal unicode format? why not...

replace n-dash

$dataold = "9am – 5pm"; // ms word doc $data = mb_ereg_replace(" – ", " - ", $dataold); print_r($data); 

replace m-dash

$dataold = "9am — 5pm"; // ms word doc $data = mb_ereg_replace(" — ", " - ", $dataold); print_r($data); 

your original code works fine, except sample text string has n-dash , you're testing m-dash. (and have spaces in regex). try this...

$dataold = "9am — 5pm"; // ms word doc $data = mb_ereg_replace("[\xe2\x80\x94]", " - ", $dataold); print_r($data); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

python - TypeError('Unrecognized keyword arguments: ' + str(kwargs)) # Validate user data -