Search code examples
phpgettextphp-gettext

php gettext fails loading html tag


I'm using gettext to translate my website. One key has a translations with a html tag:

msgid "BANNER_TAG_START"
msgstr "<!-- // MY BANNER TAG -->"

if I use this code in php now:

var_dump(htmlspecialchars(gettext('BANNER_TAG_START')));

it normally should returns:

<!-- // MY BANNER TAG -->

most times it works like this, but sometimes I get:

MY BANNER TAG

Why do I sometimes get this wrong code?


Solution

  • In my env, running the following code,

    var_dump(htmlspecialchars("<!-- // MY BANNER TAG -->"));
    

    returns this,

    string(31) "&lt;!-- // MY BANNER TAG --&gt;"
    

    not

    <!-- // MY BANNER TAG -->
    

    as you reported. So I assume you are reporting the final rendered text on your browser, instead of the generated HTML source code.

    Please check the 3-5 in 100 times where the problem happen in the generated HTML source code, and check if the what kind of other letters or line-breaks exist BEFORE the "<!-- //", then you may find the difference for the 3-5 cases.