473,471 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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?
Mar 5 '08 #1
5 2260
sp***************@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
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
Mar 5 '08 #2
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>
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.

Mar 5 '08 #3
On Wed, 05 Mar 2008 13:21:49 +0100, sp***************@gmail.com
<sp***************@gmail.comwrote:
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>>
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
Mar 5 '08 #4
On Mar 5, 1:35 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteracco...@gmail.com

<spamfilteracco...@gmail.comwrote:
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
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>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.
Mar 5 '08 #5
On Wed, 05 Mar 2008 13:53:11 +0100, sp***************@gmail.com
<sp***************@gmail.comwrote:
On Mar 5, 1:35 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>On Wed, 05 Mar 2008 13:21:49 +0100, spamfilteracco...@gmail.com

<spamfilteracco...@gmail.comwrote:
On Mar 5, 1:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>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>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
Mar 5 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news frontiernet.net | last post by:
I have key entered and tried to run example 4-6 from Dany Goodmans DYNAMIC HTML book, version one that is on pages 94-96. This is part of my effort to learn JavaScript. I checked each byte and...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
1
by: ido | last post by:
Hi all this is my first post here :) I would like to know something about using javascript programaticaly The thing is i have this web site on which when i press a button i uses a function of...
26
by: Patient Guy | last post by:
Has anyone written code that successfully manipulates binary file data using Javascript? It might---and in the case of doing I/O, will---make use of browser- specific functions (ActiveX/COM with...
8
by: shannon | last post by:
Hi there, Does anyone know if you can download a free javascript complier from the net. I need to check my code for a project. Thanks Shannon.
12
by: Water Cooler v2 | last post by:
Are JavaScript strings mutable? How're they implemented - 1. char arrays 2. linked lists of char arrays 3. another data structure I see that the + operator is overloaded for the string class...
6
by: =?Utf-8?B?Um9i?= | last post by:
Hi, If I call my own DLL from Javascript, a HRESULT is returned. Javascript cannot cast this to an integer. Is there any other way of typecasting this returnvalue to integer, wihout using the...
1
by: iporter | last post by:
Below is some VB Script - I can't figure out how to convert it to javascript. Below that, I've put my best attempt at as far as I got - can anyone help me out correcting and completing it? ...
78
by: Jeremy J Starcher | last post by:
(Request for Discussion) I've put together a guide that I hope will help novice coders avoid the same hair pulling that I went through. I'm open for comments about it. Have I missed the...
84
by: Patient Guy | last post by:
Which is the better approach in working with Javascript? 1. Server side processing: Web server gets form input, runs it into the Javascript module, and PHP collects the output for document prep....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.