This is a discussion on Assign value to variable within the PHP Language forums, part of the PHP Programming Forums category; Is there any way I can use a function to create a variable and assign a value to it? I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Is there any way I can use a function to create a variable and assign
a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering if a function exists where I can pass a variable name and a value, and the variable would be created. ie. somefunc("sn", "Shore") Would create the variable $sn and assign the value "Shore" to it. |
|
|||
|
In article <d3354680.0410080907.4c50e18b@posting.google.com >, Mike wrote:
> Is there any way I can use a function to create a variable and assign > a value to it? I have a Perl script that returns some LDAP > information: > > sn=Shore > givenname=Mike > logintime=20041008153445Z > logindisabled=FALSE > > Instead of parsing this text and assigning the values, I was wondering > if a function exists where I can pass a variable name and a value, and > the variable would be created. The output looks like what i see in a ini file, so you could consider using ini_get? -- Met vriendelijke groeten, Tim Van Wassenhove <http://www.timvw.info> |
|
|||
|
In article <2so03gF1nbi1qU1@uni-berlin.de>, Tim Van Wassenhove wrote:
> In article <d3354680.0410080907.4c50e18b@posting.google.com >, Mike wrote: >> Is there any way I can use a function to create a variable and assign >> a value to it? I have a Perl script that returns some LDAP >> information: >> >> sn=Shore >> givenname=Mike >> logintime=20041008153445Z >> logindisabled=FALSE >> >> Instead of parsing this text and assigning the values, I was wondering >> if a function exists where I can pass a variable name and a value, and >> the variable would be created. > > The output looks like what i see in a ini file, so you could consider > using ini_get? I meant http://www.php.net/parse_ini_file -- Met vriendelijke groeten, Tim Van Wassenhove <http://www.timvw.info> |
|
|||
|
I noticed that Message-ID:
<d3354680.0410080907.4c50e18b@posting.google.com > from Mike contained the following: >ie. somefunc("sn", "Shore") > >Would create the variable $sn and assign the value "Shore" to it. function somefunc($var,$value){ global $$var; $$var=$value; } somefunc("sn", "Shore"); print $sn; -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |
|
|||
|
Works like a charm. It was that double $$ that I could not wrap my
head around. Thanks very much! Geoff Berrow <blthecat@ckdog.co.uk> wrote in message news:<qhcem098np84rd76og0e2ngkqv9ro3u92c@4ax.com>. .. > I noticed that Message-ID: > <d3354680.0410080907.4c50e18b@posting.google.com > from Mike contained > the following: > > >ie. somefunc("sn", "Shore") > > > >Would create the variable $sn and assign the value "Shore" to it. > > function somefunc($var,$value){ > global $$var; > $$var=$value; > } > somefunc("sn", "Shore"); > print $sn; |
|
|||
|
I noticed that Message-ID:
<d3354680.0410261044.11722022@posting.google.com > from Mike contained the following: >Works like a charm. It was that double $$ that I could not wrap my >head around. Thanks very much! Ah, variable variables. Yep they are fun. :-) -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |
|
|||
|
Okay all you gurus, here is my next challenge :-)
I need to convert a Perl LDAP query result to an array. So far I have been able to create an variable name; for example $name = "ret[8]['givenname'][0]"; $value = "Mike" What I want to do now is assign the $value to the $name, as in $$name = $value; but that does not work. I need the end result to be: $ret[8]['givenname'][0] = "Mike"; Geoff Berrow <blthecat@ckdog.co.uk> wrote in message news:<hsj7o0l8939v88l7ma8geuocga2u2dnsa8@4ax.com>. .. > I noticed that Message-ID: > <d3354680.0410261044.11722022@posting.google.com > from Mike contained > the following: > > >Works like a charm. It was that double $$ that I could not wrap my > >head around. Thanks very much! > > Ah, variable variables. Yep they are fun. :-) |
|
|||
|
I noticed that Message-ID:
<d3354680.0411011820.5eda5ad9@posting.google.com > from Mike contained the following: >I need to convert a Perl LDAP query result to an array I don't suppose you could use the PHP LDAP functions and save some bother? -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |
|
|||
|
Hi Geoff,
I originally had everything written in PHP and it worked fine on my own test server, but then I tried it on the "official" test server it would not work. From what I have been told by our server guys, our Solaris server comes with a built in LDAP module for Netscape directories, and does not support PHP's LDAP module. So I needed to rewrite all my LDAP code in Perl, which *is* supported by the Solaris server, and then call the Perl code from LDAP, then parse the results back in PHP. *** sigh *** Geoff Berrow <blthecat@ckdog.co.uk> wrote in message news:<i7ceo09do96ae26qb7ec6baj8aurgoq5pp@4ax.com>. .. > I noticed that Message-ID: > <d3354680.0411011820.5eda5ad9@posting.google.com > from Mike contained > the following: > > >I need to convert a Perl LDAP query result to an array > > I don't suppose you could use the PHP LDAP functions and save some > bother? |
|
|||
|
I noticed that Message-ID:
<d3354680.0411021544.72504d97@posting.google.com > from Mike contained the following: >From what I have been told by our server guys, our Solaris server >comes with a built in LDAP module for Netscape directories, and does >not support PHP's LDAP module. So I needed to rewrite all my LDAP code >in Perl, which *is* supported by the Solaris server, and then call the >Perl code from LDAP, then parse the results back in PHP. *** sigh *** Just an idea because I don't know much about Perl. I do know Perl scripts echo html so why can't a perl script echo php? If this was then saved as a file it could be simply included in any php script you want. Apologies if I am wildly wrong here. -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |