Assign value to variable

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-08-2004
Mike
 
Posts: n/a
Default Assign value to variable

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.
Reply With Quote
  #2 (permalink)  
Old 10-08-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: Assign value to variable

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>
Reply With Quote
  #3 (permalink)  
Old 10-08-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: Assign value to variable

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>
Reply With Quote
  #4 (permalink)  
Old 10-09-2004
Geoff Berrow
 
Posts: n/a
Default Re: Assign value to variable

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/
Reply With Quote
  #5 (permalink)  
Old 10-26-2004
Mike
 
Posts: n/a
Default Re: Assign value to variable

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;

Reply With Quote
  #6 (permalink)  
Old 10-30-2004
Geoff Berrow
 
Posts: n/a
Default Re: Assign value to variable

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/
Reply With Quote
  #7 (permalink)  
Old 11-02-2004
Mike
 
Posts: n/a
Default Re: Assign value to variable

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. :-)

Reply With Quote
  #8 (permalink)  
Old 11-02-2004
Geoff Berrow
 
Posts: n/a
Default Re: Assign value to variable

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/
Reply With Quote
  #9 (permalink)  
Old 11-02-2004
Mike
 
Posts: n/a
Default Re: Assign value to variable

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?

Reply With Quote
  #10 (permalink)  
Old 11-03-2004
Geoff Berrow
 
Posts: n/a
Default Re: Assign value to variable

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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:45 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0