TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-09-2008, 09:11 PM   #1 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default get variable value out of a string

Hello dear colleagues from the talkphp forum,

I would very much appreciate some help regarding the following subject:

PHP Code:
$variable1 "Hello";
$title '$variable'."1";
echo 
$title
This routine is returning the result:
$variable1

I would like to get the value "Hello" instead.

Can someone explain to me which php function can I use to retrieve the result that I am looking for ?

Thanks in advance,
pipesportugal
pipesportugal is offline  
Reply With Quote
Old 11-09-2008, 10:27 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

No such function needed. The single quotes are printed literally, without printing the contents of a variable, they simply print what you've put. You can either put them all in double quotes, or in no quotes at all:

php Code:
$title = "$variable 1";
$title = $variable . "1";
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-09-2008, 10:29 PM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

There are numerous ways of doing this, here are three:
PHP Code:
$variable1 'Hello';
$title 'variable1';

echo $
$title;
// or
echo ${$title};
// or (assuming global scope)
echo $GLOBALS[$title]; 
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
pipesportugal (11-09-2008)
Old 11-09-2008, 11:08 PM   #4 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default

Hello Dear friends Wildhoney and Salathe,

Wildhoney, I think that You did not really understand what I meant, most probably by my faulty description of my needs.

Salathe, the $$ thing has solved it and was what I was looking for. I also understood the GLOBALS solution. That would also do the trick.

Thank You to both of You for disposing of Your time.

Regards,
pipesportugal
pipesportugal is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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


All times are GMT. The time now is 04:34 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design