Irish SEO,  Marketing & Webmaster Discussion

 

Can I get a variable name as a string?

This is a discussion on Can I get a variable name as a string? within the Coding Help forums, part of the Webmaster Help category; I've searching in php and perl for this: how do i get a variable name as a string e.g i ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 22-02-2007, 02:55 PM
Frontpage User
 
Join Date: Dec 2006
Posts: 20
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
montyauto will become famous soon enough
Thumbs up Can I get a variable name as a string?

I've searching in php and perl for this:

how do i get a variable name as a string e.g i have a variable
myvar:1 2 5 3 2 6 7 8
i want to get "myvar"

Is there any function to get the name of a variable based on its value?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 22-02-2007, 03:19 PM
TheMenace's Avatar
Hardcore Geek
 
Join Date: Nov 2006
Posts: 750
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
TheMenace will become famous soon enough
Send a message via MSN to TheMenace
Default

Where are you getting the name/value pairs from? A query string? Do you not know the variable names already?

I'm not sure how you do it in PHP or Perl but I'm sure there's a very simple 'get post data' function - in fact I know there is as I've seen it being used before. Google is your friend
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 22-02-2007, 04:22 PM
daviddoran's Avatar
Wannabe Geek
Recent Blog: iMSISS
 
Join Date: Aug 2006
Location: Meath, Ireland
Posts: 342
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daviddoran will become famous soon enough
Default

It seems kind of backwards, but of course possible:
Code:
<?php
function get_var( $search )
{
        $def = $GLOBALS;
        foreach( $def as $k=>$d )
        {
                if( is_string( $GLOBALS[$k] ) && $d==$search )
                {
                        return $k;
                }
        }
        return false;
}
?>
And you would use it like:
Code:
<?php
$something = 'test var';
$varname   = 'more test var';

echo get_var( 'test var' );
This would output: something
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 22-02-2007, 08:15 PM
TheMenace's Avatar
Hardcore Geek
 
Join Date: Nov 2006
Posts: 750
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
TheMenace will become famous soon enough
Send a message via MSN to TheMenace
Default

Um... anyone know PHP?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 22-02-2007, 08:22 PM
daviddoran's Avatar
Wannabe Geek
Recent Blog: iMSISS
 
Join Date: Aug 2006
Location: Meath, Ireland
Posts: 342
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daviddoran will become famous soon enough
Default

I know PHP, why are you confused?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 25-02-2007, 10:41 PM
Frontpage User
 
Join Date: Dec 2006
Posts: 20
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
montyauto will become famous soon enough
Default

Quote:
Originally Posted by daviddoran View Post
It seems kind of backwards, but of course possible:
Code:
<?php
function get_var( $search )
{
        $def = $GLOBALS;
        foreach( $def as $k=>$d )
        {
                if( is_string( $GLOBALS[$k] ) && $d==$search )
                {
                        return $k;
                }
        }
        return false;
}
?>
And you would use it like:
Code:
<?php
$something = 'test var';
$varname   = 'more test var';
 
echo get_var( 'test var' );
This would output: something
its really new to me, i have tested, it works,
thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
string, variable

Thread Tools
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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
clean up a string (123..9) louie Coding Help 1 11-01-2007 12:58 PM


Sponsored links

Paid On Results


All times are GMT +1. The time now is 04:32 AM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0