Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5074 > unrolled thread

string to array

Started by"M. Strobel" <sorry_no_mail_here@nowhere.dee>
First post2012-03-02 14:17 +0100
Last post2012-03-02 18:37 +0100
Articles 10 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 14:17 +0100
    Re: string to array Captain Paralytic <paul_lautman@yahoo.com> - 2012-03-02 06:02 -0800
      Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 18:09 +0100
        Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 13:07 -0500
    Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 09:46 -0500
      Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 18:03 +0100
        Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 13:09 -0500
          Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 19:38 +0100
            Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 14:49 -0500
      Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 18:37 +0100

#5074 — string to array

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-02 14:17 +0100
Subjectstring to array
Message-ID<9rbvjcFo5nU1@mid.uni-berlin.de>
Hi,

I am just testing with hstore in postgresql, this is a datatype providing a
key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).

The php question is:

A select from the table looks like this:

trans1=> select * from testh;
                             Tabelle testh
    n    |                              h
---------+-------------------------------------------------------------
 Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
 Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
(2 Zeilen)

And a select gives me the h column back as a string:

array(2) {
    ["n"]=>
    string(5) "Peter"
    ["h"]=>
    string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""

This looks like php source code. How could I just eval it to get a php array?

/Str.

[toc] | [next] | [standalone]


#5075

FromCaptain Paralytic <paul_lautman@yahoo.com>
Date2012-03-02 06:02 -0800
Message-ID<503439d4-1cd3-4d6c-a010-5766b540aa13@l14g2000vbe.googlegroups.com>
In reply to#5074
On Mar 2, 1:17 pm, "M. Strobel" <sorry_no_mail_h...@nowhere.dee>
wrote:
> Hi,
>
> I am just testing with hstore in postgresql, this is a datatype providing a
> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>
> The php question is:
>
> A select from the table looks like this:
>
> trans1=> select * from testh;
>                              Tabelle testh
>     n    |                              h
> ---------+-------------------------------------------------------------
>  Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>  Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
> (2 Zeilen)
>
> And a select gives me the h column back as a string:
>
> array(2) {
>     ["n"]=>
>     string(5) "Peter"
>     ["h"]=>
>     string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>
> This looks like php source code. How could I just eval it to get a php array?
>
> /Str.

At a guess
eval("\$harray=array({$result['h']});");

[toc] | [prev] | [next] | [standalone]


#5078

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-02 18:09 +0100
Message-ID<9rcd6hF45cU1@mid.uni-berlin.de>
In reply to#5075
Am 02.03.2012 15:02, schrieb Captain Paralytic:
> On Mar 2, 1:17 pm, "M. Strobel" <sorry_no_mail_h...@nowhere.dee>
> wrote:
>> Hi,
>>
>> I am just testing with hstore in postgresql, this is a datatype providing a
>> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>
>> The php question is:
>>
>> A select from the table looks like this:
>>
>> trans1=> select * from testh;
>>                              Tabelle testh
>>     n    |                              h
>> ---------+-------------------------------------------------------------
>>  Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>  Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>> (2 Zeilen)
>>
>> And a select gives me the h column back as a string:
>>
>> array(2) {
>>     ["n"]=>
>>     string(5) "Peter"
>>     ["h"]=>
>>     string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>
>> This looks like php source code. How could I just eval it to get a php array?
>>
>> /Str.
> 
> At a guess
> eval("\$harray=array({$result['h']});");
> 
 Yeah!

[toc] | [prev] | [next] | [standalone]


#5081

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-03-02 13:07 -0500
Message-ID<jir28h$mkp$1@dont-email.me>
In reply to#5078
On 3/2/2012 12:09 PM, M. Strobel wrote:
> Am 02.03.2012 15:02, schrieb Captain Paralytic:
>> On Mar 2, 1:17 pm, "M. Strobel"<sorry_no_mail_h...@nowhere.dee>
>> wrote:
>>> Hi,
>>>
>>> I am just testing with hstore in postgresql, this is a datatype providing a
>>> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>>
>>> The php question is:
>>>
>>> A select from the table looks like this:
>>>
>>> trans1=>  select * from testh;
>>>                               Tabelle testh
>>>      n    |                              h
>>> ---------+-------------------------------------------------------------
>>>   Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>>   Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>>> (2 Zeilen)
>>>
>>> And a select gives me the h column back as a string:
>>>
>>> array(2) {
>>>      ["n"]=>
>>>      string(5) "Peter"
>>>      ["h"]=>
>>>      string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>>
>>> This looks like php source code. How could I just eval it to get a php array?
>>>
>>> /Str.
>>
>> At a guess
>> eval("\$harray=array({$result['h']});");
>>
>   Yeah!

Just ensure there isn't garbage in the column - like 'rm -r /'.  eval() 
is a hacker's dream.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5076

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-03-02 09:46 -0500
Message-ID<jiqmg0$ft6$1@dont-email.me>
In reply to#5074
On 3/2/2012 8:17 AM, M. Strobel wrote:
> Hi,
>
> I am just testing with hstore in postgresql, this is a datatype providing a
> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>
> The php question is:
>
> A select from the table looks like this:
>
> trans1=>  select * from testh;
>                               Tabelle testh
>      n    |                              h
> ---------+-------------------------------------------------------------
>   Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>   Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
> (2 Zeilen)
>
> And a select gives me the h column back as a string:
>
> array(2) {
>      ["n"]=>
>      string(5) "Peter"
>      ["h"]=>
>      string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>
> This looks like php source code. How could I just eval it to get a php array?
>
> /Str.

Don't use it.  It's a bad design and fails normalization (one value in a 
column).  It also s not easily searchable nor can you modify values 
easily.  You also don't run into problems like this.

A much better way is to have a separate table with key and value columns 
and a reference column.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5077

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-02 18:03 +0100
Message-ID<9rccqeF18lU1@mid.uni-berlin.de>
In reply to#5076
Am 02.03.2012 15:46, schrieb Jerry Stuckle:
> On 3/2/2012 8:17 AM, M. Strobel wrote:
>> Hi,
>>
>> I am just testing with hstore in postgresql, this is a datatype providing a
>> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>
>> The php question is:
>>
>> A select from the table looks like this:
>>
>> trans1=>  select * from testh;
>>                               Tabelle testh
>>      n    |                              h
>> ---------+-------------------------------------------------------------
>>   Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>   Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>> (2 Zeilen)
>>
>> And a select gives me the h column back as a string:
>>
>> array(2) {
>>      ["n"]=>
>>      string(5) "Peter"
>>      ["h"]=>
>>      string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>
>> This looks like php source code. How could I just eval it to get a php array?
>>
>> /Str.
> 
> Don't use it.  It's a bad design and fails normalization (one value in a column).  It
> also s not easily searchable nor can you modify values easily.  You also don't run
> into problems like this.
> 
> A much better way is to have a separate table with key and value columns and a
> reference column.

"bad design" and "fails normalization" is generally true, but I am just fed up with
yet another properties table. hstore is made for it, it is searchable and changeable,
but nonstandard.

I think it would be an elegant solution if I would not have to read in the properties
separately, but the whole class in one take, and "explode" this string into an array.

/Str

[toc] | [prev] | [next] | [standalone]


#5082

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-03-02 13:09 -0500
Message-ID<jir2ct$mkp$2@dont-email.me>
In reply to#5077
On 3/2/2012 12:03 PM, M. Strobel wrote:
> Am 02.03.2012 15:46, schrieb Jerry Stuckle:
>> On 3/2/2012 8:17 AM, M. Strobel wrote:
>>> Hi,
>>>
>>> I am just testing with hstore in postgresql, this is a datatype providing a
>>> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>>
>>> The php question is:
>>>
>>> A select from the table looks like this:
>>>
>>> trans1=>   select * from testh;
>>>                                Tabelle testh
>>>       n    |                              h
>>> ---------+-------------------------------------------------------------
>>>    Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>>    Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>>> (2 Zeilen)
>>>
>>> And a select gives me the h column back as a string:
>>>
>>> array(2) {
>>>       ["n"]=>
>>>       string(5) "Peter"
>>>       ["h"]=>
>>>       string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>>
>>> This looks like php source code. How could I just eval it to get a php array?
>>>
>>> /Str.
>>
>> Don't use it.  It's a bad design and fails normalization (one value in a column).  It
>> also s not easily searchable nor can you modify values easily.  You also don't run
>> into problems like this.
>>
>> A much better way is to have a separate table with key and value columns and a
>> reference column.
>
> "bad design" and "fails normalization" is generally true, but I am just fed up with
> yet another properties table. hstore is made for it, it is searchable and changeable,
> but nonstandard.
>
> I think it would be an elegant solution if I would not have to read in the properties
> separately, but the whole class in one take, and "explode" this string into an array.
>
> /Str
>

Property tables are quite useful.  And how much of your design are you 
going to have to change if you do need to go to another database like 
Oracle, SQL Server, DB2 or even MySQL?

I do not like being tied to a single database.  I've seen too many 
disasters that way.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5083

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-02 19:38 +0100
Message-ID<9rcidvFdfuU1@mid.uni-berlin.de>
In reply to#5082
Am 02.03.2012 19:09, schrieb Jerry Stuckle:
> On 3/2/2012 12:03 PM, M. Strobel wrote:
>> Am 02.03.2012 15:46, schrieb Jerry Stuckle:
>>> On 3/2/2012 8:17 AM, M. Strobel wrote:
>>>> Hi,
>>>>
>>>> I am just testing with hstore in postgresql, this is a datatype providing a
>>>> key-value-store in one column
>>>> (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>>>
>>>> The php question is:
>>>>
>>>> A select from the table looks like this:
>>>>
>>>> trans1=>   select * from testh;
>>>>                                Tabelle testh
>>>>       n    |                              h
>>>> ---------+-------------------------------------------------------------
>>>>    Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>>>    Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>>>> (2 Zeilen)
>>>>
>>>> And a select gives me the h column back as a string:
>>>>
>>>> array(2) {
>>>>       ["n"]=>
>>>>       string(5) "Peter"
>>>>       ["h"]=>
>>>>       string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>>>
>>>> This looks like php source code. How could I just eval it to get a php array?
>>>>
>>>> /Str.
>>>
>>> Don't use it.  It's a bad design and fails normalization (one value in a column).  It
>>> also s not easily searchable nor can you modify values easily.  You also don't run
>>> into problems like this.
>>>
>>> A much better way is to have a separate table with key and value columns and a
>>> reference column.
>>
>> "bad design" and "fails normalization" is generally true, but I am just fed up with
>> yet another properties table. hstore is made for it, it is searchable and changeable,
>> but nonstandard.
>>
>> I think it would be an elegant solution if I would not have to read in the properties
>> separately, but the whole class in one take, and "explode" this string into an array.
>>
>> /Str
>>
> 
> Property tables are quite useful.  And how much of your design are you going to have
> to change if you do need to go to another database like Oracle, SQL Server, DB2 or
> even MySQL?
> 
> I do not like being tied to a single database.  I've seen too many disasters that way.
> 

My design is: put as much application functionality as possible in the database, then
have the option to write different front ends without having to recode all the logic.
Now I am coding triggers and functions in pltcl (yes, sending mail in pltclu from the
database, and deleting files). No option to change that.

In the last project I took over I had to rewrite important parts of a web application
only to get a ftp and sftp job entry interface.

This is the disaster I am trying to avoid.

Well, now it turns out that my php classes representing entities like users,
companies, orders, are completely independent from the web server. This is very
valuable as well, and not very difficult to do. I could use them for batch job entry,
but not for coding a fat client... (hm, you call it rich client)

So the database is there to stay.

/Str.

[toc] | [prev] | [next] | [standalone]


#5084

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-03-02 14:49 -0500
Message-ID<jir882$rk4$2@dont-email.me>
In reply to#5083
On 3/2/2012 1:38 PM, M. Strobel wrote:
> Am 02.03.2012 19:09, schrieb Jerry Stuckle:
>> On 3/2/2012 12:03 PM, M. Strobel wrote:
>>> Am 02.03.2012 15:46, schrieb Jerry Stuckle:
>>>> On 3/2/2012 8:17 AM, M. Strobel wrote:
>>>>> Hi,
>>>>>
>>>>> I am just testing with hstore in postgresql, this is a datatype providing a
>>>>> key-value-store in one column
>>>>> (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>>>>
>>>>> The php question is:
>>>>>
>>>>> A select from the table looks like this:
>>>>>
>>>>> trans1=>    select * from testh;
>>>>>                                 Tabelle testh
>>>>>        n    |                              h
>>>>> ---------+-------------------------------------------------------------
>>>>>     Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>>>>     Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>>>>> (2 Zeilen)
>>>>>
>>>>> And a select gives me the h column back as a string:
>>>>>
>>>>> array(2) {
>>>>>        ["n"]=>
>>>>>        string(5) "Peter"
>>>>>        ["h"]=>
>>>>>        string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>>>>
>>>>> This looks like php source code. How could I just eval it to get a php array?
>>>>>
>>>>> /Str.
>>>>
>>>> Don't use it.  It's a bad design and fails normalization (one value in a column).  It
>>>> also s not easily searchable nor can you modify values easily.  You also don't run
>>>> into problems like this.
>>>>
>>>> A much better way is to have a separate table with key and value columns and a
>>>> reference column.
>>>
>>> "bad design" and "fails normalization" is generally true, but I am just fed up with
>>> yet another properties table. hstore is made for it, it is searchable and changeable,
>>> but nonstandard.
>>>
>>> I think it would be an elegant solution if I would not have to read in the properties
>>> separately, but the whole class in one take, and "explode" this string into an array.
>>>
>>> /Str
>>>
>>
>> Property tables are quite useful.  And how much of your design are you going to have
>> to change if you do need to go to another database like Oracle, SQL Server, DB2 or
>> even MySQL?
>>
>> I do not like being tied to a single database.  I've seen too many disasters that way.
>>
>
> My design is: put as much application functionality as possible in the database, then
> have the option to write different front ends without having to recode all the logic.
> Now I am coding triggers and functions in pltcl (yes, sending mail in pltclu from the
> database, and deleting files). No option to change that.
>
> In the last project I took over I had to rewrite important parts of a web application
> only to get a ftp and sftp job entry interface.
>
> This is the disaster I am trying to avoid.
>
> Well, now it turns out that my php classes representing entities like users,
> companies, orders, are completely independent from the web server. This is very
> valuable as well, and not very difficult to do. I could use them for batch job entry,
> but not for coding a fat client... (hm, you call it rich client)
>
> So the database is there to stay.
>
> /Str.
>

My point being not the server - but the database.  What happens if you 
have to go to a different database?

Oh well, it will be your client who suffers, not mine.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5080

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-02 18:37 +0100
Message-ID<9rcereFgvbU1@mid.uni-berlin.de>
In reply to#5076
Am 02.03.2012 15:46, schrieb Jerry Stuckle:
> On 3/2/2012 8:17 AM, M. Strobel wrote:
>> Hi,
>>
>> I am just testing with hstore in postgresql, this is a datatype providing a
>> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>
>> The php question is:
>>
>> A select from the table looks like this:
>>
>> trans1=>  select * from testh;
>>                               Tabelle testh
>>      n    |                              h
>> ---------+-------------------------------------------------------------
>>   Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>   Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>> (2 Zeilen)
>>
>> And a select gives me the h column back as a string:
>>
>> array(2) {
>>      ["n"]=>
>>      string(5) "Peter"
>>      ["h"]=>
>>      string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>
>> This looks like php source code. How could I just eval it to get a php array?
>>
>> /Str.
> 
> Don't use it.  It's a bad design and fails normalization (one value in a column).  It

It is poaching in nonsql grounds...

/Str.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web