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:

for replacing character underscore, can modify code append '_' string if check encoding not return 1.

http://php.net/manual/en/book.mbstring.php


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -