WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding any "src=" to editor's metaboxes disrupts encoding (3 posts)

  1. TIves
    Member
    Posted 1 year ago #

    Hello all,

    I thought I had this resolved earlier, but back to the same issue.

    I have found that if I include any src= file (whether external or saved within my own directory structure) in a metabox for the edit-form-advanced.php via a plugin, the encoding becomes disrupted such that a dash ("-") becomes "—" in the tinyMCE editor window (same is true if I switch to the "HTML" view. I have no idea why or how to fix it.

    In this case, I have an file which I have "required" in many different ways (as a .js, .php, and .html file) and regardless of how I require it, it still disrupts the encoding as mentioned above.

    An image of this can be found here:
    http://financepong.com/blog/wp-content/uploads/2013/03/encoding_disruption.jpg

    Here is the entire file's content... (very simple jQuery example):

    <?php
    
    ?>
    
    <script type="text/javascript" src="/blog/wp-content/plugins/jquerylib/jquery.min.js"></script>
    <script type="text/javascript"> 
    
        $(document).ready(function(){
            $("#title").keyup(function(){alert("hello world");})
    
    }); </script>

    In the plugin file that creates the metaboxes in the editor I simply have...

    require("jquery_test.php");

    Any thoughts anyone may have would be greatly appreciated.

    Thanks so much!!

    Trip

  2. bcworkz
    Member
    Posted 1 year ago #

    It really looks like a character encoding mismatch somewhere, though I can't imagine how you get from hyphen to circumflex-a Euro. Ideally (IMO) everything should be encoded as UTF-8, regardless of what local encoding is the usual default. Doing so completely is not that simple, but WP is usually pretty good at covering most of the bases.

    Check the DB_CHARSET setting in wp-config.php matches what you find in phpMyAdmin. Apparently the encoding can be set at each level in the DB, ensure they are all consistent, the DB, each table, and each column.

    If you are using an external text editor for your coding, ensure it is also saving files in the same encoding, and that your server is running under the same. (run echo setlocale(LC_CTYPE, 0);) If you are using UTF-8, also ensure your text editor is not inserting a Byte Order Mark at the beginning of your files. You may need to view a sample file with a hex editor to verify this. If it's there, you will see 0xEF,0xBB,0xBF as the first 3 bytes before the actual data.

    If all that checks out, I am completely baffled.

    If you are really keen to go pure UTF-8, take a look at this document for all the issues involved. http://www.phpwact.org/php/i18n/charsets#character_sets_character_encoding_issues

  3. TIves
    Member
    Posted 1 year ago #

    BcWorkZ,

    Thanks so much! I read through the documentation you provided and went back to the various php files and added:

    header('Content-Type: text/html; charset=utf-8');

    and

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    where appropriate. I then reloaded the jquery library and voila, issue resolved!

    All the best!

    Trip

Topic Closed

This topic has been closed to new replies.

About this Topic