php - How to replace some characters in tsv file like HTML Math and Engineering symbol entities -
actually want replace these html math , engineering symbol entities numbers. there equivalent code ¼ ¼
, ½ ½
.
i have used str_replace
, preg_match
non of them worked. please tell me way this. highly appreciated.
you can use mb_encode_numericentity function this, http://php.net/manual/en/function.mb-encode-numericentity.php
$string = '¼ ½ ⅖ ⅘ ⅚ '; $convmap= array(0x0080, 0xffff, 0, 0xffff); $string = mb_encode_numericentity($string, $convmap, 'utf-8'); echo $string;
output:
¼ ½ ⅖ ⅘ ⅚
demo: http://sandbox.onlinephpfunctions.com/code/c554aae1696c8ded4cdd97329269828c4cbf836b
note: convert other characters outside ascii character set. if want convert 5 characters str_replace might better route.
$string = ' figure ¼,½,⅖,⅘,⅚ not'; $find = array('¼', '½', '⅖', '⅘', '⅚'); $replace = array('¼', '½', '⅖', '⅘', '⅚'); echo str_replace($find, $replace, $string);
output:
the figure ¼,½,⅖,⅘,⅚ not
demo: http://sandbox.onlinephpfunctions.com/code/e17eabdef9eabcf4f5bf4f607edddd9ac3779c75
Comments
Post a Comment