php-general Digest 11 Nov 2011 18:15:38 -0000 Issue 7562

Topics (messages 315636 through 315641):

Re: Headers already sent
        315636 by: Larry Garfield
        315637 by: Kranthi Krishna
        315639 by: Marc Guay

Re: json_encode confusion
        315638 by: Richard Quadling

Frivolous Friday Fun!
        315640 by: Jason Pruim
        315641 by: Marc Guay

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message --- Perhaps your server is configured to have output buffering enabled by default? Check php.ini / phpinfo().

--Larry Garfield

On 11/11/2011 12:12 AM, Kranthi Krishna wrote:
Hi all,

I am missing something pretty obvious here. The PHP Manual says
"Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from
PHP.". A simple test case shows otherwise

I have the following code

test
<?php
setcookie("TestCookie", 'test');

nothing more nothing less.. only this code in a file

I get the output in the browser ("test") AND the cookie is set
(verified by live HTTP headers). Any ides on why this is happening ?

Linux localhost 2.6.40-4.fc15.i686 #1 SMP Fri Jul 29 18:54:39 UTC 2011 i686
Apache 2.0 Handler
Zend Engine v2.3.0,  Xdebug v2.1.2
PHP 5.3.6

Kranthi.
http://goo.gl/e6t3


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

> Perhaps your server is configured to have output buffering enabled by default
Thanks. That was the problem. I spent a day trying to debug this.

Kranthi.
http://goo.gl/e6t3

--- End Message ---
--- Begin Message ---
> Thanks. That was the problem. I spent a day trying to debug this.

Smash head against wall first, ask questions later.  That's my
methodology as well.  :)

Marc

--- End Message ---
--- Begin Message ---
On 10 November 2011 14:45, Bastien Koert <phps...@gmail.com> wrote:
> Morning all,
>
> I've been having some fun with converting a text data file import into
> a json object for storage.
>
> I have a text file that is pipe delimited coming in via an upload. The
> first row is the headers and the second row is the data.
>
> Using this code:
>
> $data = file("inline_Nov_8_2011.txt");
>
> if(count($data)==2){
>
>        $keys   = explode("|", $data[0]);
>        $fields = explode("|", $data[1]);
>
>        $combine = array_combine($keys, $fields);
>
>        $json = json_encode($combine);
> }
>
> After the combine, I get an array that looks like this
>
> Array
> (
>    ['Legal Last Name '] => Andros
>    ['Legal Middle Initial '] =>
>    ['Legal First Name '] => Marisa
>    ['Maiden/Other Name '] =>
>    ['Social Insurance No. '] => 123456789
>    ['Date of Birth '] => 2/1/1988
>    ['Gender '] => Female
> )
>
> But the json encoded value looks like this (there are way more
> elements but this should be enough to represent what I need to do).
>
> {null:"Andros",null:"",null:"Marisa",null:"",null:"123456789",null:"2\/1\/1988",null:"Female"}
>
> I have been googling for info about allowed values for the json keys,
> but can't seem to find a clear doc on what is allowed and what isn't.
> I have tried unquoted keys, replaced the spaced with underscores but
> nothing I do seems to help.
>
> When I echo out the json encoded data, the keys are all nulls.
>
> Can someone point me in the correct direction? It may be that I need
> to manually create the key names as an array first, which I was hoping
> to avoid since the file format coming from the client is still in some
> flux.

<?php
$data = array(
   'Legal Last Name ' => 'Andros',
   'Legal Middle Initial ' => '',
   'Legal First Name ' => 'Marisa',
   'Maiden/Other Name ' => '',
   'Social Insurance No. ' => 123456789,
   'Date of Birth ' => '2/1/1988',
   'Gender ' => 'Female'
);

echo json_encode($data, JSON_FORCE_OBJECT);
?>

outputs ...

{"Legal Last Name ":"Andros","Legal Middle Initial ":"","Legal First
Name ":"Marisa","Maiden\/Other Name ":"","Social Insurance No.
":123456789,"Date of Birth ":"2\/1\/1988","Gender ":"Female"}


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc : Fantasy Shopper
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea :
fan.sh/6/370

--- End Message ---
--- Begin Message ---
The wife of a programmer to his husband:
Quote:
Darling, 
I'm starting to get a little worried about your work; you work too much... 
you spend more time with your CPU than with me... You program too much...
Her husband answers, to calm her:
Code:
!Honey; 
if(you.IsThinking(this)) !Worry;
CLove* myself = new CLove;   //I love you darling
while(world.DoExist()) 
{
     myself->m_bLoveForYou++;
     if(!myself->IsTrue())
     {
          delete myself;
          _exit(-1);
     }
}


And on a serious note... To any Past, Present, Or Future service man (Or woman) 
Thank you for your sacrifice in defending our ability to send out these 
Frivolous Friday emails! :)


Jason Pruim
li...@pruimphotography.com




--- End Message ---
--- Begin Message ---
>     if(!myself->IsTrue())
>     {
>          delete myself;
>          _exit(-1);
>     }

I like this part...


> And on a serious note... To any Past, Present, Or Future service man (Or 
> woman) Thank you for your sacrifice in defending our ability to send out 
> these Frivolous Friday emails! :)

... but not so much this part.  *I* can send Frivolous Friday emails
in spite of war, not because of it; please watch your "our"s.

Marc

--- End Message ---

Reply via email to