|
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
var data = <? echo "[...]" ?>;
results in
show/hide quoted text
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?
|
|
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
> 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 =3D <? echo "[...]" ?>;
> results in
> var data =3D <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?
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
> 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 save=
show/hide quoted text
> 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.
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
=EF=BB=BF<efbbbf>[[[ ....
;
show/hide quoted text
<efbbbf> is the BOM for UTF8
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
> 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/
|
|
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
>> 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
>> save
>> 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.
> the php file itself doesn't have a BOM.
> Here's the relevant code:
> var data =
> <?php
> $file = "data";
> if (file_exists($file))
> echo @file_get_contents($file);
> ;
> it results in
> var data =
> <efbbbf>[[[ ....
> ;
> Can file_get_contents be the cuplrit? The data file doesn't have a BOM
> either. It's PHP 5.1.4.
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 Threads | Posted | | 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 |
|