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 01-24-2008, 09:56 PM   #1 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default A little challange for you all

Well, hopefully it will be a challange

Here's what you have to do:

PHP Code:
<?php

$999 'Hello';
echo $
999;
Now, in its current state, that code won't work. Your job is to get it working

Rules: The variable name must be 999 and it must contain the string 'Hello' and you must echo the variable to display the string.

First one to post a working answer wins a cookie!

Good luck all!

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-24-2008, 10:06 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

I know, I know! But to keep it a challenge I won't reveal ! I saw this in a book I have a while ago - quite crafty, though I certainly wouldn't recommend naming your variables like this.
__________________
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 01-24-2008, 10:16 PM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

BINGO!!!!

<?php

$test = array('9','9','9');

$test[0] = "he";
$test[1] = "ll";
$test[2] = "o";
$output = "$test[0]$test[1]$test[2]";



echo $output;

?>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-24-2008, 10:17 PM   #4 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

You get half a cookie for keeping quiet

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-24-2008, 10:18 PM   #5 (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

I blogged about this sort of thing not very long ago, would it be rude to claim the cookie before many others take a stab at it? Thinking about it, lets be sporting. If you can think up any weird and wacky solutions (sarmenhb had a good stab at it!), they might not be awarded a cookie but it'll be fun anyway.
Salathe is offline  
Reply With Quote
Old 01-24-2008, 10:19 PM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Good attempt sarmenhb but there isn't a variable named 999 which contains the string 'Hello' - you have a variable called $test containing an array of 'Hello' parts

Good thinking though!

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-24-2008, 10:21 PM   #7 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Good attempt sarmenhb but there isn't a variable named 999 which contains the string 'Hello' - you have a variable called $test containing an array of 'Hello' parts

Good thinking though!

Alan

BINGO!!!

BINGO!!!!

<?php

$test = array('9','9','9');

$test[0] = "he";
$test[1] = "ll";
$test[2] = "o";
$output = "$test[0]$test[1]$test[2]";



echo $output;

?>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-24-2008, 10:27 PM   #8 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Another good attempt, but this time you are echo'ing a variable named 'output', not '999'

Keep trying though! That cookies waiting!

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-24-2008, 10:30 PM   #9 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Another good attempt, but this time you are echo'ing a variable named 'output', not '999'

Keep trying though! That cookies waiting!

Alan
lol you mentioned $output only not $test so then i can just remove $output and echo out the array.

does that work?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-24-2008, 10:32 PM   #10 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Afraid not You need to have a variable named '999', that contain the string 'Hello' (string, not array), and then echo that variable to display the string 'Hello'

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-24-2008, 10:35 PM   #11 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Afraid not You need to have a variable named '999', that contain the string 'Hello' (string, not array), and then echo that variable to display the string 'Hello'

Alan
ROFL

Code:
<?php

${999} = "hello";

echo ${999};
?>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-24-2008, 10:40 PM   #12 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

ok, turned out not to be such a challange after all :D Sarmenhb wins the Cookie!

An alternative way (and the way I was thinking of when I wrote the question is to use variable variables :)

Eg:

PHP Code:
<?php

$badName 
'999';
$
$badName 'Hello';

echo ${
'999'};
Enjoy your cookie!

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-24-2008, 10:52 PM   #13 (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

Yay, how's that cookie taste sarmenhb?

Time for some more little challenges methinks!
Salathe is offline  
Reply With Quote
Old 01-24-2008, 11:04 PM   #14 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

I suck D: (chars)
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-24-2008, 11:10 PM   #15 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

I really like this idea of challenges lol i think should have a area for these kind of challenges that the mods and admins can set maybe come up with some kind of point system

Heres one for ya

What can run but never walks, has a mouth but never talks, has a head but never weeps, has a bed but never sleeps?

__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 01-24-2008, 11:11 PM   #16 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Rendair View Post
I really like this idea of challenges lol i think should have a area for these kind of challenges that the mods and admins can set maybe come up with some kind of point system
User created challeneges, >:D I know what I'd make hehe >:D
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-25-2008, 12:27 AM   #17 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

Quote:
What can run but never walks, has a mouth but never talks, has a head but never weeps, has a bed but never sleeps?
A river

I have holes on the top and bottom. I have holes on my left and on my right. And I have holes in the middle, yet I still hold water. What am I?
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 01-25-2008, 12:39 AM   #18 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

A sponge


Temples will fall, and mountains will crumble no man can survive it's call, what am I?
TlcAndres is offline  
Reply With Quote
Old 01-25-2008, 12:56 AM   #19 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by TlcAndres View Post
A sponge


Temples will fall, and mountains will crumble now man can survive it's call, what am I?
God ( not religious >.> )
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-25-2008, 12:58 AM   #20 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

nay, though I can see where that answer would fill the perquisite answers.
TlcAndres 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 03:54 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