Remove non-utf8 characters from string

Here is a nice little PHP snippet that will remove non-ASCII characters from a String.


<?php
$string
= "Remove these characters: äó";
$string = preg_replace('/[^(\x20-\x7F)]*/','', $string);
?>

Code was taken from here.

Tags: 
PHP / MySQL

Recent Comments

Forward by Dries Buytaert, Founder and Project Lead, Drupal; CTO Acquia.

Order now from:

Managing Expectations Podcast with DrupalEasy

Author Interview http://tinyurl.com/8a8nxno

We provide the most Shiny Drupal Bits & Pixels

Since Drupal 4.x