Friday, August 10, 2012

Wordpress - eliminate non-ASCII characters

It is usual that you get special characters (or non-ASCII characters) when you try to fetch RSS feeds and display on your blog. You can easily filter it using PHP preg_replace function.

Inside a Wordpress's Post query loop, store the the content into a variable and replace all non- ASCII Characters using following code.

 <?php while (have_posts()) : the_post(); ?>
   $the_content = get_the_content();
   $the_content1 = preg_replace("/[^(\x20-\x7F)]*/","",$the_content);
   echo $the_content1;
 <?php endwhile; ?>

No comments:

Post a Comment