php-general Digest 10 Nov 2011 17:24:31 -0000 Issue 7560
Topics (messages 315621 through 315628):
Re: delete and recreate
315621 by: tamouse mailing lists
json_encode confusion
315622 by: Bastien Koert
315623 by: Dan Schaefer
315624 by: DiRaven
315625 by: DiRaven
315627 by: Jim Lucas
315628 by: Matijn Woudt
Passing arguments to an internal function via array_map
315626 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 ---
Hoisted on me own petard, as it were.
Meant this to go to OP and list, not Jim.
---------- Forwarded message ----------
From: tamouse mailing lists <tamouse.li...@gmail.com>
Date: Thu, Nov 10, 2011 at 3:25 AM
Subject: Re: [PHP] delete and recreate
To: Jim Lucas <li...@cmsws.com>
On Wed, Nov 9, 2011 at 1:44 PM, Jim Lucas <li...@cmsws.com> wrote:
> On 11/9/2011 7:35 AM, Kirk Bailey wrote:
>> So, I want to create a script to delete an old file and create a new one
>> which
>> is empty. The script receives a password via query string. The obvious
>> methods
>> give me back a very useless 500 error. Any suggestions on how to accomplish
>> what
>> I seek?
>>
>
> First, please include the at minimum the following information when asking a
> question about a problem that you are having.
>
> 1) Operating System (Windows, Linux, etc...)
> 2) Web server type and version
> 3) PHP Version ( and how it is loaded in the web server )
> 3) Example code that you have tried.
> a) What the code is doing.
> b) What you expect the code to be doing.
And while you're pondering that, make sure to read this very very
completely and take it to heart:
http://www.catb.org/~esr/faqs/smart-questions.html
--- End Message ---
--- Begin Message ---
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.
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
On 11/10/2011 09:45 AM, Bastien Koert 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.
Just a thought: Try removing the spaces altogether, not by replacing
them with underscores.
--
Dan
--- End Message ---
--- Begin Message ---
On 11/10/2011 05:45 PM, Bastien Kurt 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.
Give the incoming input example, please as well as the desired output.
--
Best regards,
DiRaven
--- End Message ---
--- Begin Message ---
On 11/10/2011 05:45 PM, Bastien Koert wrote:
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 = file("inline_Nov_8_2011.txt");
$data = array('Legal Last Name|Legal Middle Initial|Legal First
Name|Maiden/Other Name|Social Insurance No.|Date of Birth|Gender',
'Andros||Marisa||123456789|2/1/1988|Female');
$json = '';
if(count($data)==2){
$keys = explode("|", $data[0]);
$fields = explode("|", $data[1]);
$combine = array_combine($keys, $fields);
$json = json_encode($combine);
}
echo $json;
?>
That's the code I've just used.
And it gave me perfect output:
{"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"}
What version of the PHP do you use?
--
Best regards,
DiRaven
--- End Message ---
--- Begin Message ---
On 11/10/2011 6:45 AM, Bastien Koert 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.
>
Looking at your input array example, I see that you have trailing spaces in your
keys. Looking at the working example of DiRaven, the only difference that I see
with his example is that the input key values do not have a trailing spaces.
json is probably having an issue with that trailing spaces.
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/
C - (541) 408-5189
O - (541) 323-9113
H - (541) 323-4219
--- End Message ---
--- Begin Message ---
On Thu, Nov 10, 2011 at 5:42 PM, Jim Lucas <li...@cmsws.com> wrote:
> On 11/10/2011 6:45 AM, Bastien Koert 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.
>>
>
> Looking at your input array example, I see that you have trailing spaces in
> your
> keys. Looking at the working example of DiRaven, the only difference that I
> see
> with his example is that the input key values do not have a trailing spaces.
> json is probably having an issue with that trailing spaces.
>
That might be a possibility, but I suspect that the single quotes
around the keys might be a problem. I haven't tried it though.
Matijn
--- End Message ---
--- Begin Message ---
Hi folks,
I'm trying to convert the contents of an array from utf8 to utf16
(thanks for the headache MS Excel!). I originally created a "user
function" that just ran the text through
mb_convert_encoding($text,'utf-16','utf-8') but now I'm wondering if I
can't just use the internal function directly. Apparently it's more
complicated when the function requires arguments; I see example using
mysql_real_escape_string() on php.net.
My current attempt looks like this:
$clean = array_map('mb_convert_encoding', $dirty_arr, array('utf-16','utf-8'));
but I believe this is actually passing an array to
mb_convert_encoding() as the second argument rather than the 2nd and
3rd... Any ideas or am I chasing something that can't be done?
Marc
--- End Message ---