Home PHP JavaScript CSS WordPress APIs .htaccess Other How-To Useful Scripts What I Recommend
Posted on by Aleksandar Gichevski ()
In this post I will show you how you can get rid of the magical characters that sometimes show in your strings. Yea, how ofthen you opened your website and you saw stupid odd characters in your text like å ä ö √ §. Sometimes when you submit a form and store the string into the database they come up or when you copy from Word or some other text editor into content management system. Below is a regex code that you can use to remove non ascii characters, just before you use it make a test to be sure it is going to remove only the characters you want.
$str = "This text√§ contains åalso non ascii charactersö.";
$newstr = preg_replace('/[^(\x20-\x7F)]*/','', $str);
echo $newstr;
For me it did the work, hope it is going to work for u too, here is a iframe demo where you can paste your string and test...

Other Posts You Might Like

Get a fast, free website audit

Enter your URL below to get full in-depth SEO report and tips.

Useful Scripts

Most Popular Posts

Recent Posts

June 14th, 2014
Website Optimization Using Gzip Compression

June 10th, 2014
Google Search AutoComplete API

May 14th, 2014
What is a Tag Cloud and How to Calculate it by Formula

March 27th, 2014
Error writing file /tmp (errcode 28) Solved!

February 15th, 2014
Fixed CSS & HTML Navigation Bar

February 9th, 2014
Benchmark Your Server (CPU, File IO, MySQL) with SysBench

February 8th, 2014
JavaScript Array Basics

January 29th, 2014

January 25th, 2014
Payoneer Debit Card for Freelancers to receive money online

January 24th, 2014
How HTML Color Codes are generated?

Read Latest Posts directly on Facebook