Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript/PHP byte-order mark problem

spamfilteraccount@gmail.com
Guest
 
Posts: n/a
#1: Mar 5 '08
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
Guest
 
Posts: n/a
#2: Mar 5 '08

re: Javascript/PHP byte-order mark problem


spamfilteraccount@gmail.com wrote:
Quote:
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
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
spamfilteraccount@gmail.com
Guest
 
Posts: n/a
#3: Mar 5 '08

re: Javascript/PHP byte-order mark problem


On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
Quote:
>
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.

Rik Wasmus
Guest
 
Posts: n/a
#4: Mar 5 '08

re: Javascript/PHP byte-order mark problem


On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteraccount@gmail.com
<spamfilteraccount@gmail.comwrote:
Quote:
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
Quote:
>>
>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
spamfilteraccount@gmail.com
Guest
 
Posts: n/a
#5: Mar 5 '08

re: Javascript/PHP byte-order mark problem


On Mar 5, 1:35 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
Quote:
On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteracco...@gmail.com
>
<spamfilteracco...@gmail.comwrote:
Quote:
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>
Quote:
Quote:
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..
>
Quote:
I use emacs and yes it does have a built-in hex editor. :)
>
Quote:
Here's the beginning of the data file:
>
Quote:
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>undefined

;

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.
Rik Wasmus
Guest
 
Posts: n/a
#6: Mar 5 '08

re: Javascript/PHP byte-order mark problem


On Wed, 05 Mar 2008 13:53:11 +0100, spamfilteraccount@gmail.com
<spamfilteraccount@gmail.comwrote:
Quote:
On Mar 5, 1:35 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
Quote:
>On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteracco...@gmail.com
>>
><spamfilteracco...@gmail.comwrote:
Quote:
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>>
Quote:
>I'm about 99% sure the 'data' file DOES have a BOM... Do you have a
>HEX
Quote:
>editor to check it out? Be aware that offcourse most editors won't
>show
Quote:
>a
>BOM to you if they show a text file, they just interpret (or ignore)
>it.
>>
Quote:
I use emacs and yes it does have a built-in hex editor. :)
>>
Quote:
Here's the beginning of the data file:
>>
Quote:
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>undefined
>
;
>
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
Closed Thread