Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-23-2004, 04:09 PM   #1 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
Will this work?

In this topic I'm gonna throw a load of questions at the people who know some PHP to find out a few little things that has been bugging me. I ask them here as I do not know where to find the answers elsewhere.

The first question is:
Can I use a variable to store some valid php code, much like a function? I know I can use a function and be done with it but I might need to do this for some reason (who knows?!) E.G.:
PHP Code:
<?php
$Print_hello 
"echo (\"Hello, World!\");"

$Print_hello
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-23-2004, 04:24 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
nope. seems like it would make things more complicated too. there is not time i think you would need that over calling an echo or custom function.
__________________
Mike
sde is offline   Reply With Quote
Old 08-23-2004, 07:08 PM   #3 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
The first thing that pops to mind is maybe you store some php code in a db then need to retreive and execute it.

See the eval function. (lol, and oddly enough db storage of php code is the first example.)

-r
idx is offline   Reply With Quote
Old 08-23-2004, 07:23 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
i stand corrected, this code works:
PHP Code:
<?
$str 
"print('hello world');";
eval(
$str);
?>
__________________
Mike
sde is offline   Reply With Quote
Old 08-24-2004, 12:37 PM   #5 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
Can I refer to code in a database without having to use eval() ?
I've read in the php manual that it takes the page twice as long to show because it has to write and recompile twice.

Also can I use the usual within the .php doc?:
Code:
<!--#include file="SomePHPcode.txt" -->
I would test it out myself but I've yet to set up my local Apache server.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-24-2004, 06:13 PM   #6 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
No, (AFAIK) you have to first retreive the code from the DB [as a string], then use eval() to actually execute it.

The SSI might work, but it has nothing to do with PHP. PHP would just ignore it, pass it through and leave it to apache to process.

If you wanted to include (print) the contents of a file in PHP:

PHP Code:
readfile('SomePHPCode.txt'); 
...but to actually execute the code within that file:

PHP Code:
require 'SomePHPCode.txt';

// or
require_once 'SomePHPCode.txt'
See the docs on require
and include

-r
idx is offline   Reply With Quote
Reply

Bookmarks

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Multidimensional arrays work like a hash in Perl? philthee Java 1 10-22-2004 02:06 PM
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outloo gicio MS Technologies ( ASP, VB, C#, .NET ) 0 12-10-2003 11:05 AM
San Diego Tech. work. Admin Lounge 10 02-03-2003 07:19 PM
Getting X to work in Debian w00t Linux / BSD / OS X 7 08-25-2002 02:44 PM


All times are GMT -8. The time now is 06:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting