passaf
passaf

Reputation:

Strange characters in PHP

This is driving me crazy.

I have this one php file on a test server at work which does not work.. I kept deleting stuff from it till it became

<?
print 'Hello';
?>

it outputs

Hello

if I create a new file and copy / paste the same script to it it works! Why does this one file give me the strange characters all the time?

Upvotes: 10

Views: 1865

Answers (3)

passaf
passaf

Reputation:

Just in case, here is a list of bytes for BOM

Encoding    Representation (hexadecimal)
UTF-8   EF BB BF
UTF-16 (BE) FE FF
UTF-16 (LE) FF FE
UTF-32 (BE) 00 00 FE FF
UTF-32 (LE) FF FE 00 00
UTF-7   2B 2F 76, and one of the following bytes: [ 38 | 39 | 2B | 2F ]†
UTF-1   F7 64 4C
UTF-EBCDIC  DD 73 66 73
SCSU    0E FE FF
BOCU-1  FB EE 28 optionally followed by FF†

Upvotes: 2

Pat
Pat

Reputation: 36702

That's the BOM (Byte Order Mark) you are seeing.

In your editor, there should be a way to force saving without BOM which will remove the problem.

Upvotes: 16

passaf
passaf

Reputation:

Found it, file -> encoding -> UTF8 with BOM , changed to to UTF :-)

I should ahve asked before wasing time trying to figure it out :-)

Upvotes: 3

Related Questions