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

java - unable show chart in xls document using jasper reports -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -

javascript - How to change image src on success AJAX -