php-general Digest 12 Apr 2011 13:40:15 -0000 Issue 7270

Topics (messages 312338 through 312354):

Eliminatimg PHP UTF-8 BOM in a returned stream to a Mobile App
        312338 by: Eli Orr
        312342 by: Richard Quadling
        312346 by: Eli Orr
        312348 by: Richard Quadling
        312349 by: Richard Quadling
        312350 by: Eli Orr
        312351 by: Eli Orr
        312353 by: Richard Quadling

Re: Error in variable assignment
        312339 by: Richard Quadling

a shortcut to set variable
        312340 by: Joe Francis
        312341 by: David Robley
        312343 by: Stuart Dallas
        312344 by: tedd
        312345 by: Stuart Dallas
        312347 by: Richard Quadling
        312352 by: tedd
        312354 by: Richard Quadling

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Dear PHP Gurus, 

I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:

The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the beginning of
UTF-8  files) which 
consists of three bytes: EF BB BF.   

The Mobile App served by the server Does not need that. How can I eliminate
it??

Thanks.

UTF-8 Byte Order Mark – BOM:
http://unicode.org/faq/utf_bom.html#BOM

Best Regards, 

Eli  Orr
CTO & Founder 
Mimmage.com 
My virtual vCard 
LogoDial Ltd.
M:+972-54-7379604
O:+972-74-703-2034
F: +972-77-3379604

Plaut 10, Rehovot, Israel 
Email:   [email protected]
Skype:  eliorr.com


----- 



--- End Message ---
--- Begin Message ---
2011/4/12 Eli Orr <[email protected]>:
> Dear PHP Gurus,
>
> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>
> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the beginning of
> UTF-8  files) which
> consists of three bytes: EF BB BF.
>
> The Mobile App served by the server Does not need that. How can I eliminate
> it??
>
> Thanks.
>
> UTF-8 Byte Order Mark – BOM:
> http://unicode.org/faq/utf_bom.html#BOM
>
> Best Regards,
>
> Eli  Orr
> CTO & Founder
> Mimmage.com
> My virtual vCard
> LogoDial Ltd.
> M:+972-54-7379604
> O:+972-74-703-2034
> F: +972-77-3379604
>
> Plaut 10, Rehovot, Israel
> Email:   [email protected]
> Skype:  eliorr.com
>
>
> -----
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Can you show us the PHP script that DOES output the BOM?

Normally, PHP doesn't do this automatically (AFAIK). The main reason
being is that it is often the case that the BOM appears in the source
code file before the <?php opening tag, so would block headers
(session cookie for example).

If a BOM is being issued by PHP, it is being done programmatically, or
is being missed due to the initial source code file having the BOM
set.

See http://docs.php.net/manual/en/function.session-start.php#102431,
http://docs.php.net/manual/en/function.header.php#95864, etc.

Now. Having said all of that, you may find you are using some sort of
output buffering and that is setting the BOM after the headers are
sent.

But, as it stands, PHP will not be generating the BOM for you.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
Hi Richard, 

Thanks.
Indeed, that is the case - I've included a code that has UTF-8 string contants 
-so I guess the PHP 
parser set the UTF-8 mode to ON so that the returned string to the client has 
the UTF-8 BOM. 

It is not a big issue as the mobile app guys aware of this and make the proper 
3 bytes offset.
Anyhow I was looking for a service to control that behaviour. 

 Thanks

Eli

-----Original Message-----
From: Richard Quadling [mailto:[email protected]] 
Sent: Tuesday, April 12, 2011 12:45 PM
To: Eli Orr
Cc: [email protected]
Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a Mobile 
App

2011/4/12 Eli Orr <[email protected]>:
> Dear PHP Gurus,
>
> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>
> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the 
> beginning of
> UTF-8  files) which
> consists of three bytes: EF BB BF.
>
> The Mobile App served by the server Does not need that. How can I 
> eliminate it??
>
> Thanks.
>
> UTF-8 Byte Order Mark – BOM:
> http://unicode.org/faq/utf_bom.html#BOM
>
> Best Regards,
>
> Eli  Orr
> CTO & Founder
> Mimmage.com
> My virtual vCard
> LogoDial Ltd.
> M:+972-54-7379604
> O:+972-74-703-2034
> F: +972-77-3379604
>
> Plaut 10, Rehovot, Israel
> Email:   [email protected]
> Skype:  eliorr.com
>
>
> -----
>
>
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
> http://www.php.net/unsub.php
>
>

Can you show us the PHP script that DOES output the BOM?

Normally, PHP doesn't do this automatically (AFAIK). The main reason being is 
that it is often the case that the BOM appears in the source code file before 
the <?php opening tag, so would block headers (session cookie for example).

If a BOM is being issued by PHP, it is being done programmatically, or is being 
missed due to the initial source code file having the BOM set.

See http://docs.php.net/manual/en/function.session-start.php#102431,
http://docs.php.net/manual/en/function.header.php#95864, etc.

Now. Having said all of that, you may find you are using some sort of output 
buffering and that is setting the BOM after the headers are sent.

But, as it stands, PHP will not be generating the BOM for you.

--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
On 12 April 2011 11:59, Eli Orr <[email protected]> wrote:
>
> Hi Richard,
>
> Thanks.
> Indeed, that is the case - I've included a code that has UTF-8 string 
> contants -so I guess the PHP
> parser set the UTF-8 mode to ON so that the returned string to the client has 
> the UTF-8 BOM.
>
> It is not a big issue as the mobile app guys aware of this and make the 
> proper 3 bytes offset.
> Anyhow I was looking for a service to control that behaviour.
>
>  Thanks
>
> Eli
>
> -----Original Message-----
> From: Richard Quadling [mailto:[email protected]]
> Sent: Tuesday, April 12, 2011 12:45 PM
> To: Eli Orr
> Cc: [email protected]
> Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a Mobile 
> App
>
> 2011/4/12 Eli Orr <[email protected]>:
>> Dear PHP Gurus,
>>
>> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>>
>> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the
>> beginning of
>> UTF-8  files) which
>> consists of three bytes: EF BB BF.
>>
>> The Mobile App served by the server Does not need that. How can I
>> eliminate it??
>>
>> Thanks.
>>
>> UTF-8 Byte Order Mark – BOM:
>> http://unicode.org/faq/utf_bom.html#BOM
>>
>> Best Regards,
>>
>> Eli  Orr
>> CTO & Founder
>> Mimmage.com
>> My virtual vCard
>> LogoDial Ltd.
>> M:+972-54-7379604
>> O:+972-74-703-2034
>> F: +972-77-3379604
>>
>> Plaut 10, Rehovot, Israel
>> Email:   [email protected]
>> Skype:  eliorr.com
>>
>>
>> -----
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
>> http://www.php.net/unsub.php
>>
>>
>
> Can you show us the PHP script that DOES output the BOM?
>
> Normally, PHP doesn't do this automatically (AFAIK). The main reason being is 
> that it is often the case that the BOM appears in the source code file before 
> the <?php opening tag, so would block headers (session cookie for example).
>
> If a BOM is being issued by PHP, it is being done programmatically, or is 
> being missed due to the initial source code file having the BOM set.
>
> See http://docs.php.net/manual/en/function.session-start.php#102431,
> http://docs.php.net/manual/en/function.header.php#95864, etc.
>
> Now. Having said all of that, you may find you are using some sort of output 
> buffering and that is setting the BOM after the headers are sent.
>
> But, as it stands, PHP will not be generating the BOM for you.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
> http://www.php.net/unsub.php
>
>
>

No. The parser does not _ADD_ the BOM.

The bom already exists in your source code. Nothing to do with PHP.

The file you included that has the UTF-8 constants has the BOM.

You need to edit that file and remove the BOM. The actions you need to
take will depend upon your editor.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 12 April 2011 12:50, Richard Quadling <[email protected]> wrote:
> On 12 April 2011 11:59, Eli Orr <[email protected]> wrote:
>>
>> Hi Richard,
>>
>> Thanks.
>> Indeed, that is the case - I've included a code that has UTF-8 string 
>> contants -so I guess the PHP
>> parser set the UTF-8 mode to ON so that the returned string to the client 
>> has the UTF-8 BOM.
>>
>> It is not a big issue as the mobile app guys aware of this and make the 
>> proper 3 bytes offset.
>> Anyhow I was looking for a service to control that behaviour.
>>
>>  Thanks
>>
>> Eli
>>
>> -----Original Message-----
>> From: Richard Quadling [mailto:[email protected]]
>> Sent: Tuesday, April 12, 2011 12:45 PM
>> To: Eli Orr
>> Cc: [email protected]
>> Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a 
>> Mobile App
>>
>> 2011/4/12 Eli Orr <[email protected]>:
>>> Dear PHP Gurus,
>>>
>>> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>>>
>>> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the
>>> beginning of
>>> UTF-8  files) which
>>> consists of three bytes: EF BB BF.
>>>
>>> The Mobile App served by the server Does not need that. How can I
>>> eliminate it??
>>>
>>> Thanks.
>>>
>>> UTF-8 Byte Order Mark – BOM:
>>> http://unicode.org/faq/utf_bom.html#BOM
>>>
>>> Best Regards,
>>>
>>> Eli  Orr
>>> CTO & Founder
>>> Mimmage.com
>>> My virtual vCard
>>> LogoDial Ltd.
>>> M:+972-54-7379604
>>> O:+972-74-703-2034
>>> F: +972-77-3379604
>>>
>>> Plaut 10, Rehovot, Israel
>>> Email:   [email protected]
>>> Skype:  eliorr.com
>>>
>>>
>>> -----
>>>
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
>>> http://www.php.net/unsub.php
>>>
>>>
>>
>> Can you show us the PHP script that DOES output the BOM?
>>
>> Normally, PHP doesn't do this automatically (AFAIK). The main reason being 
>> is that it is often the case that the BOM appears in the source code file 
>> before the <?php opening tag, so would block headers (session cookie for 
>> example).
>>
>> If a BOM is being issued by PHP, it is being done programmatically, or is 
>> being missed due to the initial source code file having the BOM set.
>>
>> See http://docs.php.net/manual/en/function.session-start.php#102431,
>> http://docs.php.net/manual/en/function.header.php#95864, etc.
>>
>> Now. Having said all of that, you may find you are using some sort of output 
>> buffering and that is setting the BOM after the headers are sent.
>>
>> But, as it stands, PHP will not be generating the BOM for you.
>>
>> --
>> Richard Quadling
>> Twitter : EE : Zend
>> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>>
>> --
>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
>> http://www.php.net/unsub.php
>>
>>
>>
>
> No. The parser does not _ADD_ the BOM.
>
> The bom already exists in your source code. Nothing to do with PHP.
>
> The file you included that has the UTF-8 constants has the BOM.
>
> You need to edit that file and remove the BOM. The actions you need to
> take will depend upon your editor.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>

To be a bit more specific...

The BOM is the 3 bytes you correctly identified earlier.

Most editors won't show these when you edit the files.

But, for the sake of argument, let's just pretend they are visible and
look like ...

#@&

In the php script that contains some UTF-8 constants, the file would
look like ...

#@&<php
echo '₩'; // The Fullwidth Won sign.
?>

As PHP will only actually parse the content between <?php and ?>, the
#@& string (the BOM) is simply sent straight through to the web server
-> the client with no interruption.

Now, if your code was ...

#@&<php
session_start();
?>

you would see the headers already sent error message, as the BOM tells
the webserver that data is now being received and to send any headers
it already has.

So when the session_start() wants to send the session cookie (which is
done as a HTTP Header), PHP already knows some content has gone (the
BOM) and reports the error.

To iterate, PHP is NOT generating the BOM. You already did that in
your code. Well, the editor did it for you.

Ideally, you want to turn off the BOM in your editor.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---

Thanks Richard, 

Do you know a technique to mirror all the echo strings into a file for 
debugging ?

Eli

-----Original Message-----
From: Richard Quadling [mailto:[email protected]] 
Sent: Tuesday, April 12, 2011 2:51 PM
To: Eli Orr
Cc: [email protected]
Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a Mobile 
App

On 12 April 2011 11:59, Eli Orr <[email protected]> wrote:
>
> Hi Richard,
>
> Thanks.
> Indeed, that is the case - I've included a code that has UTF-8 string 
> contants -so I guess the PHP parser set the UTF-8 mode to ON so that the 
> returned string to the client has the UTF-8 BOM.
>
> It is not a big issue as the mobile app guys aware of this and make the 
> proper 3 bytes offset.
> Anyhow I was looking for a service to control that behaviour.
>
>  Thanks
>
> Eli
>
> -----Original Message-----
> From: Richard Quadling [mailto:[email protected]]
> Sent: Tuesday, April 12, 2011 12:45 PM
> To: Eli Orr
> Cc: [email protected]
> Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a 
> Mobile App
>
> 2011/4/12 Eli Orr <[email protected]>:
>> Dear PHP Gurus,
>>
>> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>>
>> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the 
>> beginning of
>> UTF-8  files) which
>> consists of three bytes: EF BB BF.
>>
>> The Mobile App served by the server Does not need that. How can I 
>> eliminate it??
>>
>> Thanks.
>>
>> UTF-8 Byte Order Mark – BOM:
>> http://unicode.org/faq/utf_bom.html#BOM
>>
>> Best Regards,
>>
>> Eli  Orr
>> CTO & Founder
>> Mimmage.com
>> My virtual vCard
>> LogoDial Ltd.
>> M:+972-54-7379604
>> O:+972-74-703-2034
>> F: +972-77-3379604
>>
>> Plaut 10, Rehovot, Israel
>> Email:   [email protected]
>> Skype:  eliorr.com
>>
>>
>> -----
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
>> http://www.php.net/unsub.php
>>
>>
>
> Can you show us the PHP script that DOES output the BOM?
>
> Normally, PHP doesn't do this automatically (AFAIK). The main reason being is 
> that it is often the case that the BOM appears in the source code file before 
> the <?php opening tag, so would block headers (session cookie for example).
>
> If a BOM is being issued by PHP, it is being done programmatically, or is 
> being missed due to the initial source code file having the BOM set.
>
> See http://docs.php.net/manual/en/function.session-start.php#102431,
> http://docs.php.net/manual/en/function.header.php#95864, etc.
>
> Now. Having said all of that, you may find you are using some sort of output 
> buffering and that is setting the BOM after the headers are sent.
>
> But, as it stands, PHP will not be generating the BOM for you.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
> http://www.php.net/unsub.php
>
>
>

No. The parser does not _ADD_ the BOM.

The bom already exists in your source code. Nothing to do with PHP.

The file you included that has the UTF-8 constants has the BOM.

You need to edit that file and remove the BOM. The actions you need to take 
will depend upon your editor.

--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
Hi Richard, 

Thanks. 
I've already got a solution to simply use Notes++ and save the PHP script 
with Save As encoding set to ANSI (It was UTF-8 indeed that creates the BOM...).

Thanks again

Eli

-----Original Message-----
From: Richard Quadling [mailto:[email protected]] 
Sent: Tuesday, April 12, 2011 2:59 PM
To: Eli Orr
Cc: [email protected]
Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a Mobile 
App

On 12 April 2011 12:50, Richard Quadling <[email protected]> wrote:
> On 12 April 2011 11:59, Eli Orr <[email protected]> wrote:
>>
>> Hi Richard,
>>
>> Thanks.
>> Indeed, that is the case - I've included a code that has UTF-8 string 
>> contants -so I guess the PHP parser set the UTF-8 mode to ON so that the 
>> returned string to the client has the UTF-8 BOM.
>>
>> It is not a big issue as the mobile app guys aware of this and make the 
>> proper 3 bytes offset.
>> Anyhow I was looking for a service to control that behaviour.
>>
>>  Thanks
>>
>> Eli
>>
>> -----Original Message-----
>> From: Richard Quadling [mailto:[email protected]]
>> Sent: Tuesday, April 12, 2011 12:45 PM
>> To: Eli Orr
>> Cc: [email protected]
>> Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to 
>> a Mobile App
>>
>> 2011/4/12 Eli Orr <[email protected]>:
>>> Dear PHP Gurus,
>>>
>>> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>>>
>>> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the 
>>> beginning of
>>> UTF-8  files) which
>>> consists of three bytes: EF BB BF.
>>>
>>> The Mobile App served by the server Does not need that. How can I 
>>> eliminate it??
>>>
>>> Thanks.
>>>
>>> UTF-8 Byte Order Mark – BOM:
>>> http://unicode.org/faq/utf_bom.html#BOM
>>>
>>> Best Regards,
>>>
>>> Eli  Orr
>>> CTO & Founder
>>> Mimmage.com
>>> My virtual vCard
>>> LogoDial Ltd.
>>> M:+972-54-7379604
>>> O:+972-74-703-2034
>>> F: +972-77-3379604
>>>
>>> Plaut 10, Rehovot, Israel
>>> Email:   [email protected]
>>> Skype:  eliorr.com
>>>
>>>
>>> -----
>>>
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
>>> http://www.php.net/unsub.php
>>>
>>>
>>
>> Can you show us the PHP script that DOES output the BOM?
>>
>> Normally, PHP doesn't do this automatically (AFAIK). The main reason being 
>> is that it is often the case that the BOM appears in the source code file 
>> before the <?php opening tag, so would block headers (session cookie for 
>> example).
>>
>> If a BOM is being issued by PHP, it is being done programmatically, or is 
>> being missed due to the initial source code file having the BOM set.
>>
>> See http://docs.php.net/manual/en/function.session-start.php#102431,
>> http://docs.php.net/manual/en/function.header.php#95864, etc.
>>
>> Now. Having said all of that, you may find you are using some sort of output 
>> buffering and that is setting the BOM after the headers are sent.
>>
>> But, as it stands, PHP will not be generating the BOM for you.
>>
>> --
>> Richard Quadling
>> Twitter : EE : Zend
>> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>>
>> --
>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
>> http://www.php.net/unsub.php
>>
>>
>>
>
> No. The parser does not _ADD_ the BOM.
>
> The bom already exists in your source code. Nothing to do with PHP.
>
> The file you included that has the UTF-8 constants has the BOM.
>
> You need to edit that file and remove the BOM. The actions you need to 
> take will depend upon your editor.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>

To be a bit more specific...

The BOM is the 3 bytes you correctly identified earlier.

Most editors won't show these when you edit the files.

But, for the sake of argument, let's just pretend they are visible and look 
like ...

#@&

In the php script that contains some UTF-8 constants, the file would look like 
...

#@&<php
echo '₩'; // The Fullwidth Won sign.
?>

As PHP will only actually parse the content between <?php and ?>, the #@& 
string (the BOM) is simply sent straight through to the web server
-> the client with no interruption.

Now, if your code was ...

#@&<php
session_start();
?>

you would see the headers already sent error message, as the BOM tells the 
webserver that data is now being received and to send any headers it already 
has.

So when the session_start() wants to send the session cookie (which is done as 
a HTTP Header), PHP already knows some content has gone (the
BOM) and reports the error.

To iterate, PHP is NOT generating the BOM. You already did that in your code. 
Well, the editor did it for you.

Ideally, you want to turn off the BOM in your editor.

--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
On 12 April 2011 13:29, Eli Orr <[email protected]> wrote:
> Hi Richard,
>
> Thanks.
> I've already got a solution to simply use Notes++ and save the PHP script
> with Save As encoding set to ANSI (It was UTF-8 indeed that creates the 
> BOM...).
>
> Thanks again
>
> Eli
>
> -----Original Message-----
> From: Richard Quadling [mailto:[email protected]]
> Sent: Tuesday, April 12, 2011 2:59 PM
> To: Eli Orr
> Cc: [email protected]
> Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to a Mobile 
> App
>
> On 12 April 2011 12:50, Richard Quadling <[email protected]> wrote:
>> On 12 April 2011 11:59, Eli Orr <[email protected]> wrote:
>>>
>>> Hi Richard,
>>>
>>> Thanks.
>>> Indeed, that is the case - I've included a code that has UTF-8 string
>>> contants -so I guess the PHP parser set the UTF-8 mode to ON so that the 
>>> returned string to the client has the UTF-8 BOM.
>>>
>>> It is not a big issue as the mobile app guys aware of this and make the 
>>> proper 3 bytes offset.
>>> Anyhow I was looking for a service to control that behaviour.
>>>
>>>  Thanks
>>>
>>> Eli
>>>
>>> -----Original Message-----
>>> From: Richard Quadling [mailto:[email protected]]
>>> Sent: Tuesday, April 12, 2011 12:45 PM
>>> To: Eli Orr
>>> Cc: [email protected]
>>> Subject: Re: [PHP] Eliminatimg PHP UTF-8 BOM in a returned stream to
>>> a Mobile App
>>>
>>> 2011/4/12 Eli Orr <[email protected]>:
>>>> Dear PHP Gurus,
>>>>
>>>> I would like to Eliminate the 3 UTF-8 BOM enforced on my returned BLOB:
>>>>
>>>> The PHP server adds  utf-8 BOM (UTF-8 Byte Order Mark  - in the
>>>> beginning of
>>>> UTF-8  files) which
>>>> consists of three bytes: EF BB BF.
>>>>
>>>> The Mobile App served by the server Does not need that. How can I
>>>> eliminate it??
>>>>
>>>> Thanks.
>>>>
>>>> UTF-8 Byte Order Mark – BOM:
>>>> http://unicode.org/faq/utf_bom.html#BOM
>>>>
>>>> Best Regards,
>>>>
>>>> Eli  Orr
>>>> CTO & Founder
>>>> Mimmage.com
>>>> My virtual vCard
>>>> LogoDial Ltd.
>>>> M:+972-54-7379604
>>>> O:+972-74-703-2034
>>>> F: +972-77-3379604
>>>>
>>>> Plaut 10, Rehovot, Israel
>>>> Email:   [email protected]
>>>> Skype:  eliorr.com
>>>>
>>>>
>>>> -----
>>>>
>>>>
>>>>
>>>> --
>>>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
>>>> http://www.php.net/unsub.php
>>>>
>>>>
>>>
>>> Can you show us the PHP script that DOES output the BOM?
>>>
>>> Normally, PHP doesn't do this automatically (AFAIK). The main reason being 
>>> is that it is often the case that the BOM appears in the source code file 
>>> before the <?php opening tag, so would block headers (session cookie for 
>>> example).
>>>
>>> If a BOM is being issued by PHP, it is being done programmatically, or is 
>>> being missed due to the initial source code file having the BOM set.
>>>
>>> See http://docs.php.net/manual/en/function.session-start.php#102431,
>>> http://docs.php.net/manual/en/function.header.php#95864, etc.
>>>
>>> Now. Having said all of that, you may find you are using some sort of 
>>> output buffering and that is setting the BOM after the headers are sent.
>>>
>>> But, as it stands, PHP will not be generating the BOM for you.
>>>
>>> --
>>> Richard Quadling
>>> Twitter : EE : Zend
>>> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
>>> http://www.php.net/unsub.php
>>>
>>>
>>>
>>
>> No. The parser does not _ADD_ the BOM.
>>
>> The bom already exists in your source code. Nothing to do with PHP.
>>
>> The file you included that has the UTF-8 constants has the BOM.
>>
>> You need to edit that file and remove the BOM. The actions you need to
>> take will depend upon your editor.
>>
>> --
>> Richard Quadling
>> Twitter : EE : Zend
>> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>>
>
> To be a bit more specific...
>
> The BOM is the 3 bytes you correctly identified earlier.
>
> Most editors won't show these when you edit the files.
>
> But, for the sake of argument, let's just pretend they are visible and look 
> like ...
>
> #@&
>
> In the php script that contains some UTF-8 constants, the file would look 
> like ...
>
> #@&<php
> echo '₩'; // The Fullwidth Won sign.
> ?>
>
> As PHP will only actually parse the content between <?php and ?>, the #@& 
> string (the BOM) is simply sent straight through to the web server
> -> the client with no interruption.
>
> Now, if your code was ...
>
> #@&<php
> session_start();
> ?>
>
> you would see the headers already sent error message, as the BOM tells the 
> webserver that data is now being received and to send any headers it already 
> has.
>
> So when the session_start() wants to send the session cookie (which is done 
> as a HTTP Header), PHP already knows some content has gone (the
> BOM) and reports the error.
>
> To iterate, PHP is NOT generating the BOM. You already did that in your code. 
> Well, the editor did it for you.
>
> Ideally, you want to turn off the BOM in your editor.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
> http://www.php.net/unsub.php
>
>
>

Hmmm. You really want to save the code as UTF-8 without BOM.

What is the editor? The references for Notes++ I can find is for a
post-it notes app.






-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 11 April 2011 20:28, Ethan Rosenberg <[email protected]> wrote:
> Dear list -
>
> I an writing a script that will simulate a chess board.  On a move from e2
> to e6 [see below] the variable in e2 is never assigned to e6.  Here are some
> code snippets:
>
> <?php
> session_start();
> session_name("Chess");
> error_reporting(1);
>  if ($_SESSION['flag'] != 1)
> {
> $flag = 1;
> echo "<br />starting<br />";
>  $results = array(array("Br", "Bn", "Bb", "Bq", "Bk", "Bb", "Bn",
> "Br"),array("Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp"),
>                        array("", "", "", "", "", "", "", ""),array("", "",
> "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),
>                        array("", "", "", "", "", "", "", ""),array("Wp",
> "Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp"),
>                        array("Wr", "Wn", "Wb", "Wq", "Wk", "Wb", "Wn",
> "Wr"));
>
> $_SESSION['results'] = $results;
>        for($i = 0; $i <8; $i++)
>        {
>                for ($j = 0; $j < 8; $j++)
>                        printf("%s ", $results[$i][$j]);
>                printf("<br />");
>        }
>
> $_SESSION[flag] = $flag;
>
> <snip>
>
> $board = array  //Correlation of input array [chessboard] with internal
> array [results]
> (
>                "a8" => $results[0][0],
>                "b8" => $results[0][1],
>                "c8" => $results[0][2],
>                "d8" => $results[0][3],
>                "e8" => $results[0][4],
>                "f8" => $results[0][5],
>                "g8" => $results[0][6],
>                "h8" => $results[0][7],
>                "a7" => $results[1][0],
>                "b7" => $results[1][1],
>                "c7" => $results[1][2],
>                "d7" => $results[1][3],
>                "e7" => $results[1][4],
>                "f7" => $results[1][5],
>                "g7" => $results[1][6],
>                "h7" => $results[1][7],
>                "a6" => $results[2][0],
>                "b6" => $results[2][1],
>                "c6" => $results[2][2],
>                "d6" => $results[2][3],
>                "e6" => $results[2][4],
>                "f6" => $results[2][5],
>                "g6" => $results[2][6],
>                "h6" => $results[2][7],
>                "a5" => $results[3][0],
>                "b5" => $results[3][1],
>                "c5" => $results[3][2],
>                "d5" => $results[3][3],
>                "e5" => $results[3][4],
>                "f5" => $results[3][5],
>                "g5" => $results[3][6],
>                "h5" => $results[3][7],
>                "a4" => $results[4][0],
>                "b4" => $results[4][1],
>                "c4" => $results[4][2],
>                "d4" => $results[4][3],
>                "e4" => $results[4][4],
>                "f4" => $results[4][5],
>                "g4" => $results[4][6],
>                "h4" => $results[4][7],
>                "a3" => $results[5][0],
>                "b3" => $results[5][1],
>                "c3" => $results[5][2],
>                "d3" => $results[5][3],
>                "e3" => $results[5][4],
>                "f3" => $results[5][5],
>                "g3" => $results[5][6],
>                "h3" => $results[5][7],
>                "a2" => $results[6][0],
>                "b2" => $results[6][1],
>                "c2" => $results[6][2],
>                "d2" => $results[6][3],
>                "e2" => $results[6][4],
>                "f2" => $results[6][5],
>                "g2" => $results[6][6],
>                "h2" => $results[6][7],
>                "a1" => $results[7][0],
>                "b1" => $results[7][1],
>                "c1" => $results[7][2],
>                "d1" => $results[7][3],
>                "e1" => $results[7][4],
>                "f1" => $results[7][5],
>                "g1" => $results[7][6],
>                "h1" => $results[7][7],
>        );
>
>
> $board2 = array  //Correlation of input array [chessboard] with internal
> array [results]
> (
>                "a8" => "[0][0]",
>                "b8" => "[0][1]",
>                "c8" => "[0][2]",
>                "d8" => "[0][3]",
>                "e8" => "[0][4]",
>                "f8" => "[0][5]",
>                "g8" => "[0][6]",
>                "h8" => "[0][7]",
>                "a7" => "[1][0]",
>                "b7" => "[1][1]",
>                "c7" => "[1][2]",
>                "d7" => "[1][3]",
>                "e7" => "[1][4]",
>                "f7" => "[1][5]",
>                "g7" => "[1][6]",
>                "h7" => "[1][7]",
>                "a6" => "[2][0]",
>                "b6" => "[2][1]",
>                "c6" => "[2][2]",
>                "d6" => "[2][3]",
>                "e6" => "[2][4]",
>                "f6" => "[2][5]",
>                "g6" => "[2][6]",
>                "h6" => "[2][7]",
>                "a5" => "[3][0]",
>                "b5" => "[3][1]",
>                "c5" => "[3][2]",
>                "d5" => "[3][3]",
>                "e5" => "[3][4]",
>                "f5" => "[3][5]",
>                "g5" => "[3][6]",
>                "h5" => "[3][7]",
>                "a4" => "[4][0]",
>                "b4" => "[4][1]",
>                "c4" => "[4][2]",
>                "d4" => "[4][3]",
>                "e4" => "[4][4]",
>                "f4" => "[4][5]",
>                "g4" => "[4][6]",
>                "h4" => "[4][7]",
>                "a3" => "[5][0]",
>                "b3" => "[5][1]",
>                "c3" => "[5][2]",
>                "d3" => "[5][3]",
>                "e3" => "[5][4]",
>                "f3" => "[5][5]",
>                "g3" => "[5][6]",
>                "h3" => "[5][7]",
>                "a2" => "[6][0]",
>                "b2" => "[6][1]",
>                "c2" => "[6][2]",
>                "d2" => "[6][3]",
>                "e2" => "[6][4]",
>                "f2" => "[6][5]",
>                "g2" => "[6][6]",
>                "h2" => "[6][7]",
>                "a1" => "[7][0]",
>                "b1" => "[7][1]",
>                "c1" => "[7][2]",
>                "d1" => "[7][3]",
>                "e1" => "[7][4]",
>                "f1" => "[7][5]",
>                "g1" => "[7][6]",
>                "h1" => "[7][7]",
>        );
>        $results = $_SESSION['results'];
>
>        $a = "$";
>        $a .="results";
>        $a .= "$board2[$value_from]";
>
>        $b = "$";
>        $b .="results";
>        $b .= "$board2[$value_to]";
>
>        $bb = $board[$value_to];
>        $aa = $board[$value_from];
>
>        $b = $aa;
>        $a = '';
> ========
> I am not able to assign the value Wp to $b which is $results[2][4]. $a,
> which is $results[6][4] should be empty.
>
> Help and advice, please.
>
> Ethan
>
> MySQL 5.1  PHP 5.3.3-6  Linux [Debian (sid)]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You are suppressing errors (at least based upon the code you've supplied).

Change ...

error_reporting(1); // Will only report E_ERROR - Fatal run-time
errors. These indicate errors that can not be recovered from, such as
a memory allocation problem. Execution of the script is halted.

to

error_reporting(-1); // Shows everything. The code you've supplied is
missing the values for the $value_from and $value_to.

--- End Message ---
--- Begin Message ---
eh, I just want to get a shortcut like

$id = isset($_GET['id']) ? $_GET['id'] : 0;


BTW, I'm using PHP5.3+, thanks bros.

-- 
Powered By Francis™.
Welcome to my website: http://www.francistm.com
Rewrite to [email protected] please.

--- End Message ---
--- Begin Message ---
Joe Francis wrote:

> eh, I just want to get a shortcut like
> 
> $id = isset($_GET['id']) ? $_GET['id'] : 0;
> 
> 
> BTW, I'm using PHP5.3+, thanks bros.
> 

That should work - what is not happening that you expect to happen, or the
other way round? 


Cheers
-- 
David Robley

The best way to keep friends is not to give them away.
Today is Boomtime, the 29th day of Discord in the YOLD 3177. 


--- End Message ---
--- Begin Message ---
On Tuesday, 12 April 2011 at 10:36, Joe Francis wrote:
eh, I just want to get a shortcut like
> 
> $id = isset($_GET['id']) ? $_GET['id'] : 0;
> 
> 
> BTW, I'm using PHP5.3+, thanks bros.

http://stut.net/2011/04/12/php-snippet-array-element-access/

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/



--- End Message ---
--- Begin Message ---
At 11:06 AM +0100 4/12/11, Stuart Dallas wrote:
On Tuesday, 12 April 2011 at 10:36, Joe Francis wrote:
eh, I just want to get a shortcut like

 $id = isset($_GET['id']) ? $_GET['id'] : 0;


 BTW, I'm using PHP5.3+, thanks bros.

http://stut.net/2011/04/12/php-snippet-array-element-access/

-Stuart

--
Stuart Dallas

Stuart:

Interesting and nice idea (your snippets). I'm sure it's easier for you to read, but my first thought about V() is huh? In truth, it would take me a while to get used to it and if I came across it in someone else's code I would find it more confusing than a ternary operator.

Questions:

1. Why "V"? Does that stand for Variable?

2. Why the "()" in:

$var = (isset($_GET['var']) ? $_GET['var']) : '');

Why not?

$var = isset($_GET['var']) ? $_GET['var']) : '';

3. Are the "Ramblings of a random software engineer" the "Ramblings of a random-software engineer" or the "Ramblings of a random software-engineer" ?

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On Tuesday, 12 April 2011 at 11:52, tedd wrote:
At 11:06 AM +0100 4/12/11, Stuart Dallas wrote:
> > On Tuesday, 12 April 2011 at 10:36, Joe Francis wrote:
> > eh, I just want to get a shortcut like
> > > 
> > >  $id = isset($_GET['id']) ? $_GET['id'] : 0;
> > > 
> > > 
> > >  BTW, I'm using PHP5.3+, thanks bros.
> > 
> > http://stut.net/2011/04/12/php-snippet-array-element-access/
> > 
> > -Stuart
> > 
> > --
> > Stuart Dallas
> 
> Stuart:
> 
> Interesting and nice idea (your snippets). I'm sure it's easier for 

I've changed the syntax highlighter I use, so I really need to go back over 
previous snippets and fix them!

> you to read, but my first thought about V() is huh? In truth, it 
> would take me a while to get used to it and if I came across it in 
> someone else's code I would find it more confusing than a ternary 
> operator.

Then calling it ifsetor would probably work better.

> Questions:
> 
> 1. Why "V"? Does that stand for Variable?

Yup.

> 2. Why the "()" in:
> 
> $var = (isset($_GET['var']) ? $_GET['var']) : '');
> 
> Why not?
> 
> $var = isset($_GET['var']) ? $_GET['var']) : '';

Clarity-based habit. They are in no way necessary.

> 3. Are the "Ramblings of a random software engineer" the "Ramblings 
> of a random-software engineer" or the "Ramblings of a random 
> software-engineer" ?

Take your pick. I'm available for contract work, and a lot of that is random!

:)

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/






--- End Message ---
--- Begin Message ---
On 12 April 2011 11:57, Stuart Dallas <[email protected]> wrote:
> On Tuesday, 12 April 2011 at 11:52, tedd wrote:
> At 11:06 AM +0100 4/12/11, Stuart Dallas wrote:
>> > On Tuesday, 12 April 2011 at 10:36, Joe Francis wrote:
>> > eh, I just want to get a shortcut like
>> > >
>> > >  $id = isset($_GET['id']) ? $_GET['id'] : 0;
>> > >
>> > >
>> > >  BTW, I'm using PHP5.3+, thanks bros.
>> >
>> > http://stut.net/2011/04/12/php-snippet-array-element-access/
>> >
>> > -Stuart
>> >
>> > --
>> > Stuart Dallas
>>
>> Stuart:
>>
>> Interesting and nice idea (your snippets). I'm sure it's easier for
>
> I've changed the syntax highlighter I use, so I really need to go back over 
> previous snippets and fix them!
>
>> you to read, but my first thought about V() is huh? In truth, it
>> would take me a while to get used to it and if I came across it in
>> someone else's code I would find it more confusing than a ternary
>> operator.
>
> Then calling it ifsetor would probably work better.
>
>> Questions:
>>
>> 1. Why "V"? Does that stand for Variable?
>
> Yup.
>
>> 2. Why the "()" in:
>>
>> $var = (isset($_GET['var']) ? $_GET['var']) : '');
>>
>> Why not?
>>
>> $var = isset($_GET['var']) ? $_GET['var']) : '';
>
> Clarity-based habit. They are in no way necessary.
>
>> 3. Are the "Ramblings of a random software engineer" the "Ramblings
>> of a random-software engineer" or the "Ramblings of a random
>> software-engineer" ?
>
> Take your pick. I'm available for contract work, and a lot of that is random!
>
> :)
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Putting () around ternary's is a "best practise".

<?php
echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are
not.', ' Ready state completed', PHP_EOL;
$go = true;
echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are
not.', ' Ready state completed', PHP_EOL;
?>

vs.

<?php
echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are
not.' . ' Ready state completed' . PHP_EOL;
$go = true;
echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are
not.' . ' Ready state completed' . PHP_EOL;
?>

vs.

<?php
echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are
not.') . ' Ready state completed' . PHP_EOL;
$go = true;
echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are
not.') . ' Ready state completed' . PHP_EOL;
?>

Don't run them just yet.

Can you quickly and easily see the output?



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
At 12:47 PM +0100 4/12/11, Richard Quadling wrote:
Putting () around ternary's is a "best practise".

<?php
echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are
not.', ' Ready state completed', PHP_EOL;
$go = true;
echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are
not.', ' Ready state completed', PHP_EOL;
?>

vs.

<?php
echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are
not.' . ' Ready state completed' . PHP_EOL;
$go = true;
echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are
not.' . ' Ready state completed' . PHP_EOL;
?>

vs.

<?php
echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are
not.') . ' Ready state completed' . PHP_EOL;
$go = true;
echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are
not.') . ' Ready state completed' . PHP_EOL;
?>

Don't run them just yet.

Can you quickly and easily see the output?

Argg!  :-)

$ready = 'Are we ready to go? ';
$yes = 'Yes we are.';
$no = 'No we are not.'

echo($ready);
echo(isset($go) ? $yes : $no);


Cheers,

tedd


--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On 12 April 2011 14:25, tedd <[email protected]> wrote:
> At 12:47 PM +0100 4/12/11, Richard Quadling wrote:
>>
>> Putting () around ternary's is a "best practise".
>>
>> <?php
>> echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are
>> not.', ' Ready state completed', PHP_EOL;
>> $go = true;
>> echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are
>> not.', ' Ready state completed', PHP_EOL;
>> ?>
>>
>> vs.
>>
>> <?php
>> echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are
>> not.' . ' Ready state completed' . PHP_EOL;
>> $go = true;
>> echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are
>> not.' . ' Ready state completed' . PHP_EOL;
>> ?>
>>
>> vs.
>>
>> <?php
>> echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are
>> not.') . ' Ready state completed' . PHP_EOL;
>> $go = true;
>> echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are
>> not.') . ' Ready state completed' . PHP_EOL;
>> ?>
>>
>> Don't run them just yet.
>>
>> Can you quickly and easily see the output?
>
> Argg!  :-)
>
> $ready = 'Are we ready to go? ';
> $yes = 'Yes we are.';
> $no = 'No we are not.'
>
> echo($ready);
> echo(isset($go) ? $yes : $no);
>
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Tedd,

echo is a construct and the () are not required. ;-p


The purpose of the code was not to demonstrate any particular coding
style, but what happens if you use a ternary without () around it.

Without running the code, can you say what the output will be in the 3 examples?



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---

Reply via email to