SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert Extended ASCII to ASCII

    I am looking for a function which can convert Extended ASCII to normal ASCII. I hardly can't believe PHP doesn't have a standard function for this.

    Itrntinliztin
    should for example be converted into.
    Internationalizaetion

    I am definitely not looking for htmlentities or something else. As I need to interface with an external device.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't think PHP has one off the shell, but using a ASCII table, the ord() and chr() functions you should be able to create one easily. Just make an array mapping extended ascii values to basic ascii values (eg 130 -> 101) and iterate over your string, replacing characters where needed.

  3. #3
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't utf8_decode help you?
    Also check some of the comments on that page. If not, the above solution by Радич will work fine as well.
    Yves Janse:
    Android42.net - PHP5 Bookcase project - Developers Blog
    | PHP | MySQL | CSS | XML | XHTML | AJAX | Patterns |

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    I18n

    Quote Originally Posted by Piett
    I hardly can't believe PHP doesn't have a standard function for this.
    Think about it. The task is certainly non-trivial! Besides using ord (the online docs have examples of how to use it) http://www.php.net/manual/en/function.ord.php
    There are PEAR packages you may find useful.
    http://pear.php.net/packages.php?cat...ationalization
    http://pear.php.net/manual/en/packag...ion.i18nv2.php
    http://pear.php.net/manual/en/packag...anslation2.php
    http://www.phpclasses.org/browse/package/557.html
    maybe http://www.onlamp.com/pub/a/php/2002.../php_i18n.html

  5. #5
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Why do you want to convert to o? They are two entirely different letters.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already have an array replace function like Радич suggested. I hoped some native function would have been available for this.

    I need to convert to o as I need to interface with a device display which can only show ASCII > 31 and ASCII < 128. o is the nearest looking char. Otherwise it will display a space for every unrecognized char.

    Itrntinliztin would than be shown as
    I t rn ti n liz t n
    while
    Internationalizaetion would be much nicer.

  7. #7
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    The letter is a ligature of oe. You have to use either or oe - using o makes no sense.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •