Tech Scraps

Friday, January 11, 2008

Removing all non-ASCII characters from a string using php

ASCII characters have hex code from 00 to 7F (http://www.asciitable.com/).

Following php function removes all non-ASCII characters from a string:

function removeNonAscii($string) {
return preg_replace('/[^\x00-\x7f]/','',$string);
}
Posted by Vivek at 4:11 AM
Labels: ascii, php, special characters

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2011 (1)
    • ►  June (1)
  • ►  2010 (18)
    • ►  November (1)
    • ►  September (2)
    • ►  August (13)
    • ►  July (1)
    • ►  January (1)
  • ►  2009 (14)
    • ►  September (2)
    • ►  August (1)
    • ►  July (1)
    • ►  June (3)
    • ►  April (1)
    • ►  March (1)
    • ►  February (4)
    • ►  January (1)
  • ▼  2008 (22)
    • ►  December (1)
    • ►  November (3)
    • ►  July (1)
    • ►  May (2)
    • ►  April (1)
    • ►  February (5)
    • ▼  January (9)
      • Buying the WRT54G Wireless Router in India
      • Hosting multiple sites on a single server using th...
      • Finding Intersections between two sets in C++
      • Technologies to look out for in 2008
      • Removing all non-ASCII characters from a string us...
      • Reliance Broadnet (Broadband internet connection)
      • Set Clipboard contents from command line using java
      • Capturing string input without echo in java
      • Hibernate instead of Shutdown for faster performance
  • ►  2007 (3)
    • ►  December (3)

Twitter Updates

Twitter Updates

    follow me on Twitter
    Simple theme. Powered by Blogger.