Results 1 to 3 of 3

Thread: text field read file need help with encode UTF-8

  1. #1
    Join Date
    Apr 2010
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default text field read file need help with encode UTF-8

    I have posted this on another forum to try and get help but was unsuccessful.

    My text field reads a text file but the text file contains UTF-8 and when the text field reads it i get all jibberish text. E.G. -Ŧķ-κıℓℓεя comes out as -Ŧķ-κıℓℓεÑ

    I did try something like the following.

    PHP Code:
    <?php 
    $myFile 
    "includes/docs/sdata.txt";
    $fh fopen($myFile'r');
    $theData fread($fhfilesize($theData));
    fclose($fh);
    function 
    fixEncoding($theData)
    {
      
    $cur_encoding mb_detect_encoding($theData) ;
      if(
    $cur_encoding == "UTF-8" && mb_check_encoding($theData,"UTF-8"))
        return 
    $theData;
      else
        return 
    utf8_encode($theData);
    // fixEncoding
    echo '<span id="sprytextfield1">
    <label for="templateedit">Edit template script</label><br /><textarea name="templateedit" cols="90" rows="90" id="templateedit">' 
    $theData '</textarea>
    <span class="textfieldRequiredMsg">A value is required.</span></span></div>'
    ?>
    But clearly that is wrong or something in there is wrong

    I am newish to php so you have to bare with my n00bish code.

    Help would be greatly appriciated

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This isn't a complete answer yet, but there are many possible problems with encoding. Make sure that ALL text is always stored and displayed as UTF8. For example, there must be a meta tag on the page that does this, in addition to the format of the text file. A database might also cause more compatibility issues. Once all of this is correct, it'll be a lot easier to fix. What you have above may work fine, but that only works if you've correctly diagnosed where the problem is and unfortunately in encoding problems it often is in an unexpected place.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    Tim Dobson (07-03-2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    This isn't a complete answer yet, but there are many possible problems with encoding. Make sure that ALL text is always stored and displayed as UTF8. For example, there must be a meta tag on the page that does this, in addition to the format of the text file. A database might also cause more compatibility issues. Once all of this is correct, it'll be a lot easier to fix. What you have above may work fine, but that only works if you've correctly diagnosed where the problem is and unfortunately in encoding problems it often is in an unexpected place.
    ACHHHHHHHHHH meta tag!!! lol thanks it completely flew right over my head. Added the meta tag and woop it come out corretly. You i see what you mean by being "unexpected" i must of missed the meta tag in the file somewhere

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
  •