Click here to get back home

Javascript/PHP byte-order mark problem

 HomeNewsGroups | Search

comp.lang.php - PHP programming language discussions 

get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Javascript/PHP byte-order mark problem spamfilteraccount@gmail.com 03-05-2008
Posted by spamfilteraccount@gmail.com on March 5, 2008, 3:42 am
Please log in for more thread options
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:

show/hide quoted text

results in

show/hide quoted text

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?

Posted by Rik Wasmus on March 5, 2008, 6:05 am
Please log in for more thread options
On Wed, 05 Mar 2008 09:42:06 +0100, spamfilteraccount@gmail.com =


show/hide quoted text

Save the file as UTF-8 WITHOUT BOM? A BOM is not needed for UTF-8, and =

AFAIK PHP doesn't prepend any BOM itself, save for actual content in the=
=

file (which would offcourse always be before the opening <?php tag, as =

they're the first bytes of a document, and hence will be sent without =

being processed by PHP). Any self respecting editor should be able to sa=
ve =

a file in UTF-8 without a BOM. I suspect the javascript code is an =

include/require rather then an echo, am I right? If not, please provide =
=

the relevent portion of the real code.
-- =

Rik Wasmus

Posted by spamfilteraccount@gmail.com on March 5, 2008, 6:59 am
Please log in for more thread options
show/hide quoted text

show/hide quoted text

Hi


the php file itself doesn't have a BOM.

Here's the relevant code:

var data =3D

=EF=BB=BF<?php

$file =3D "data";
if (file_exists($file))
echo @file_get_contents($file);
else
echo "undefined";

show/hide quoted text
;


it results in

var data =3D

show/hide quoted text

;


show/hide quoted text

Can file_get_contents be the cuplrit? The data file doesn't have a BOM
either. It's PHP 5.1.4.


Posted by Toby A Inkster on March 5, 2008, 7:01 am
Please log in for more thread options
spamfilteraccount@gmail.com wrote:

show/hide quoted text

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/

Posted by Rik Wasmus on March 5, 2008, 7:14 am
Please log in for more thread options
On Wed, 05 Mar 2008 12:59:27 +0100, spamfilteraccount@gmail.com

show/hide quoted text

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.
--
Rik Wasmus

Similar ThreadsPosted
echo with question mark August 26, 2006, 1:34 pm
help : apostrophe/single quotation mark March 6, 2007, 4:32 am
question mark in serialized object August 20, 2007, 2:13 pm
question mark url encoding causes errors May 11, 2008, 6:27 pm
web caching tutorial by Mark Nottingham November 11, 2008, 10:47 am
how to mark php document as cachable (expires only when php filechanges) August 19, 2005, 12:15 am
Echo versus Question Mark Equals August 6, 2007, 4:05 pm
strange extra quote mark appearing in mysql query October 24, 2006, 5:39 am
Newbie question: variable setting trough question mark July 17, 2004, 2:26 pm
newbie question: setting a variable from browser using question mark July 17, 2004, 7:05 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap
Privacy Policy