variables as statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tmjp.com
Forum Newbie
Posts: 3
Joined: Thu Dec 11, 2003 6:00 am
Location: Ipswich UK

variables as statements

Post by tmjp.com »

Hello,

I'm relatively new to php and was wondering...

...Is it possible to write a statement into a variable, then access the variable as though it were the results of executing the statement?

EG

<?php
$thingamebob = "1 + 1";
echo("$thingamebob");
?>

writes

1 + 1

Is there a way to get it to write

2

without going into complex regexps and stuff.


Hope someone can help.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

the eval() funtion may be helpful!?

http://se.php.net/manual/en/function.eval.php

Mark
tmjp.com
Forum Newbie
Posts: 3
Joined: Thu Dec 11, 2003 6:00 am
Location: Ipswich UK

Post by tmjp.com »

Yippeee.

Ta. You're a scholar and a gent.

If only I knew what to search for, I'd search for it.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

google is your friend :)
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

Download the PHP manual :D
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

You can also (if you use mozilla firebird ..if not you should use it) add a search engine on php.net (by clicking on the google search engine in the toolbar (top right corner) and selecting add engine
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Or, add a bookmark, but the URL as this:

Code: Select all

javascript: var the_answer = prompt('Which function?', 'Enter here'); document.location = 'http://sg.php.net/' + the_answer;
8).

-Nay
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

or create a quicksearch boookmark in your mozilla browser
php -> http://php.net/%s
and type php eval ;)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

volka <_<...

viewtopic.php?t=15541

Some things never change do they? ;)

-Nay
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

we will see ;)
Post Reply