PHP : Removing Non-English Characters From String.

By | April 10, 2013

Hey Folks,

The below code will help you to remove non-english characters from your PHP variable string.

<?php
$string = "somAe7 სოფო_$ tഞാൻext"; 
$string = preg_replace('/[^a-z]/i', '', $string); 

echo $string; //Outputs somAetext
?>

If you want to include numbers & space from the above string, Use below code.

<?php
$string = "somAe7 სოფო_$ tഞാൻext"; 
$string = preg_replace('/[^a-z0-9_ ]/i', '', $string); 

echo $string; //Outputs somAe7 text
?>

Cheers,
JENSon.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *