php - How to remove unwanted ascii characters from string? -
i have string shown below
$string1="then & add â...“ to";
the special ascii characters â “ Â etc. causing errors.
so want know there default function or ways remove such characters?
expected output after processing :
$string1="then & add … to";
you need mb_string installed , enabled in php.ini (which default now). on centos install php-mbstring package , restart web server, if running via web.
<?php $string = "aâ"; print $string . "\n"; $length = mb_strlen( $string ); $index = 0; $output = ''; while( $index < $length ) { $char = $string[$index]; if( mb_check_encoding( $char, 'ascii') ) { $output .= $string[$index]; } $index++; } print $output . "\n"; ?>
result:
aâ
for replacing character underscore, can modify code append '_' string if check encoding not return 1.
Comments
Post a Comment