Javascript/PHP byte-order mark problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • spamfilteraccount@gmail.com

    Javascript/PHP byte-order mark problem

    Hi,

    I have a PHP file which outputs javascript code. It works well in
    Firefox, but Opera chokes on it.

    The problem is the PHP file contains UTF characters, so when I output
    javascript code with PHP echo, then PHP prepends the output with an
    UTF BOM:

    var data = <? echo "[...]" ?>;

    results in

    var data = <BOM>[...];

    Opera doesn't like the BOM within javascript code, it indicates a
    syntax error. I cannot save the PHP file as non-UTF, because other
    parts of it have UTF characters.

    Is there a workaround for this? Is there a way to prevent echo from
    outputting a BOM when the page itself is UTF?
  • Toby A Inkster

    #2
    Re: Javascript/PHP byte-order mark problem

    spamfilteraccou nt@gmail.com wrote:
    The data file doesn't have a BOM either.
    Are you double-sure about that? It seems to be the only explanation to me.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 35 days, 18:17.]

    Bottled Water

    Comment

    • spamfilteraccount@gmail.com

      #3
      Re: Javascript/PHP byte-order mark problem

      On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
      >
      I'm about 99% sure the 'data' file DOES have a BOM... Do you have a HEX
      editor to check it out? Be aware that offcourse most editors won't show a
      BOM to you if they show a text file, they just interpret (or ignore) it.
      I use emacs and yes it does have a built-in hex editor. :)

      Here's the beginning of the data file:

      00000000: 5b5b 5b22 3437 2e34 3935 3736 3022 2c22 [[["47.495760" ,"
      ....


      I'm at loss.

      Comment

      • Rik Wasmus

        #4
        Re: Javascript/PHP byte-order mark problem

        On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteraccou nt@gmail.com
        <spamfilteracco unt@gmail.comwr ote:
        On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
        >>
        >I'm about 99% sure the 'data' file DOES have a BOM... Do you have a HEX
        >editor to check it out? Be aware that offcourse most editors won't show
        >a
        >BOM to you if they show a text file, they just interpret (or ignore) it.
        >
        I use emacs and yes it does have a built-in hex editor. :)
        >
        Here's the beginning of the data file:
        >
        00000000: 5b5b 5b22 3437 2e34 3935 3736 3022 2c22 [[["47.495760" ,"
        ...
        Are you looking at the real file, or some file that you uploaded? I seem
        to remember some FTP clients abominable behaviour (aaargh, DON'T mess with
        files)...

        I've never seen PHP put in a BOM that wasn't actually there, so if it
        isn't, I'm thorougly at a loss.
        --
        Rik Wasmus

        Comment

        • spamfilteraccount@gmail.com

          #5
          Re: Javascript/PHP byte-order mark problem

          On Mar 5, 1:35 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
          On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteracco. ..@gmail.com
          >
          <spamfilteracco ...@gmail.comwr ote:
          On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
          >
          I'm about 99% sure the 'data' file DOES have a BOM... Do you have a HEX
          editor to check it out? Be aware that offcourse most editors won't show
          a
          BOM to you if they show a text file, they just interpret (or ignore) it..
          >
          I use emacs and yes it does have a built-in hex editor. :)
          >
          Here's the beginning of the data file:
          >
          00000000: 5b5b 5b22 3437 2e34 3935 3736 3022 2c22 [[["47.495760" ,"
          ...
          >
          Are you looking at the real file, or some file that you uploaded? I seem
          to remember some FTP clients abominable behaviour (aaargh, DON'T mess with
          files)...
          I tested the other branch when the file doesn't exist. The result:

          var data =

          <efbbbf>unde fined

          ;

          Scary, isn't it? :)

          I checked the PHP file again and it turned out the BOM was in the
          file itself outside of the PHP section. I don't know any good reason
          how it could get there, but it was there, so PHP was innocent.

          Thanks for the help everyone and sorry for the noise. Anyway, this
          thread may be helpful for someone who runs into the same problem
          later.

          Comment

          • Rik Wasmus

            #6
            Re: Javascript/PHP byte-order mark problem

            On Wed, 05 Mar 2008 13:53:11 +0100, spamfilteraccou nt@gmail.com
            <spamfilteracco unt@gmail.comwr ote:
            On Mar 5, 1:35 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
            >On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteracco. ..@gmail.com
            >>
            ><spamfilteracc o...@gmail.comw rote:
            On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
            >>
            >I'm about 99% sure the 'data' file DOES have a BOM... Do you have a
            >HEX
            >editor to check it out? Be aware that offcourse most editors won't
            >show
            >a
            >BOM to you if they show a text file, they just interpret (or ignore)
            >it.
            >>
            I use emacs and yes it does have a built-in hex editor. :)
            >>
            Here's the beginning of the data file:
            >>
            00000000: 5b5b 5b22 3437 2e34 3935 3736 3022 2c22 [[["47.495760" ,"
            ...
            >>
            >Are you looking at the real file, or some file that you uploaded? I seem
            >to remember some FTP clients abominable behaviour (aaargh, DON'T mess
            >with
            >files)...
            >
            I tested the other branch when the file doesn't exist. The result:
            >
            var data =
            >
            <efbbbf>unde fined
            >
            ;
            >
            Scary, isn't it? :)
            >
            I checked the PHP file again and it turned out the BOM was in the
            file itself outside of the PHP section. I don't know any good reason
            how it could get there, but it was there, so PHP was innocent.
            >
            Thanks for the help everyone and sorry for the noise. Anyway, this
            thread may be helpful for someone who runs into the same problem
            later.
            Hmm, seems like a weird copy/paste action with an editor either to smart
            for it's own good or to simple :P. I'd be highly tempted to check with a
            possibly employed version control system when this was actually
            introduced. Glad we have it solved, and there's not some weird bug in PHP
            :).
            --
            Rik Wasmus

            Comment

            Working...