SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Encoding Issues

  1. #1
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Encoding Issues

    I'm using fopen and fwrite to edit the .htaccess file in wordpress. Although it works fine I have a user complaining that the encoding has been changed from us-ascii to ISO-8859. Any suggestions on how to prevent this?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    One thing you can try is overwriting the content type header using PHP's header() function, i have personally never seen it used like this before but it might be worth a shot.

    PHP Code:
    <?php

    // Overwrite the content-type using a header statement
    header('Content-Type: text/html; charset=us-ascii');

    // Your fopen/fwrite code here....

    ?>

  3. #3
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Sgt. I had been thinking of that, however the code in question is a Wordpress plugin and the user is concerned with how the file is actually saved. I wouldn't think this would fix the matter....

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Why not force a blanket encoding via .htaccess?
    Code:
    AddDefaultCharset UTF-8
    I must admit, I'm not entirely sure what your issue is though. If it's the contents of the file, can you not utf8_encode the string prior to writing it?

    Off Topic:

    Happy Birthday.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Anthony, I'm not entirely sure of the clients issue myself. The script uses fopen and fwrite to add lines to the .htaccess in a wordpress install. He's been complaining to me that after the write his file changes in the filesystem from us-ascii to 8859-iso. Personally I can't see what the issue is if it is being served up by apache without problems, but as I promised him I'm trying to see if I can figure out anymore. Perhaps there is an aspect of the inner workings of fopen that I'm missing.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I don't think fwrite and such are encoding aware, nor dependent. You could however, try setting mb_internal_encoding to see if that helps.

    Other than that, I'm stumped.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good suggestion. I'll take a look. Thanks!


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
  •