Can't remove special characters with str_replace

后端 未结 8 670
北荒
北荒 2020-12-07 04:00

I have a very trivial problem with str_replace.

I have a string with the En Dash character ( - ) like this:

I want to remove - the dash
8条回答
  •  温柔的废话
    2020-12-07 04:41

    I tried everything and nothing worked. but in the end with the help of http://www.ascii.cl/htmlcodes.htm

    this code did work for me

            $arr1 = explode(",","0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F");
            $arr2 = explode(",","B,C,D,E,F");
    
            foreach($arr2 as $t1){
                foreach($arr1 as $t2){
                    $val = $t1.$t2;
                    $desc = str_replace(chr(hexdec($val)),"",$desc);
                }   
            }
    
            // if need removing individual value
            $desc = str_replace(chr(hexdec('A2')),"",$desc);
    

提交回复
热议问题