Jump to content

Making a variable php code


cinos11

Recommended Posts

I need to make a variable php code so i can include it in one of my files.

 

I need it to be like:

$testimony = ('include($_SERVER['DOCUMENT_ROOT'].'/page/testimony/customer_testomonies.php')')

but that does not work and i get the error

Parse error: syntax error, unexpected T_STRING in C:\Server\www\myserver.dev\vhost\REMOVED\public\page.php on line 2

 

The page that will be using the variable will include the file and have: <?php $testimony ?>

 

How do i get it to work properly without the error?

Link to comment
Share on other sites

Well if i do double quotes for a change i get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Server\www\myserver.dev\vhost\REMOVED\public\page.php on line 2

 

using new quotes the code looks like:

$testimony = ("include($_SERVER['DOCUMENT_ROOT'].'/page/testimony/customer_testomonies.php')")

Link to comment
Share on other sites

At above when i tried your code i get the error:

 

Parse error: syntax error, unexpected T_VARIABLE in C:\Server\www\myserver.dev\vhost\AquaDrilling\public\page.php on line 3

 

EDIT: Also because you added eval to your post, how would i add it to my code of

$testimony = ("include(".$_SERVER['DOCUMENT_ROOT']."/page/testimony/customer_testomonies.php)")

Link to comment
Share on other sites

EDIT: Also because you added eval to your post, how would i add it to my code of

$testimony = ("include(".$_SERVER['DOCUMENT_ROOT']."/page/testimony/customer_testomonies.php)")

 

the change would be done here

<?php $testimony ?>

 

use eval on $testimony... see if that works

Link to comment
Share on other sites

What you are doing in not clear and what you have shown makes no sense (it also violates one of the prime rules of programming, the separation of code and data. Your data should not contain code.)

 

You can use a variable as the argument that the include statement operates on and the code (the include) does not need to be part of the data.

 

 

Link to comment
Share on other sites

What you are doing in not clear and what you have shown makes no sense (it also violates one of the prime rules of programming, the separation of code and data. Your data should not contain code.)

 

You can use a variable as the argument that the include statement operates on and the code (the include) does not need to be part of the data.

 

This doesn't make very much sense.

How am i going to include something if the include does not need to be part of the data.

Link to comment
Share on other sites

What you are doing in not clear and what you have shown makes no sense (it also violates one of the prime rules of programming, the separation of code and data. Your data should not contain code.)

 

You can use a variable as the argument that the include statement operates on and the code (the include) does not need to be part of the data.

 

he means changing:

 

$testimony = ("include(".$_SERVER['DOCUMENT_ROOT']."/page/testimony/customer_testomonies.php)");

 

to:

 

$testimony = ($_SERVER['DOCUMENT_ROOT']."/page/testimony/customer_testomonies.php");

 

and changing:

 

<?php $testimony ?>

 

to:

 

<?php include($testimony); ?>

Link to comment
Share on other sites

What you are doing in not clear and what you have shown makes no sense (it also violates one of the prime rules of programming, the separation of code and data. Your data should not contain code.)

 

You can use a variable as the argument that the include statement operates on and the code (the include) does not need to be part of the data.

 

he means changing:

 

$testimony = ("include(".$_SERVER['DOCUMENT_ROOT']."/page/testimony/customer_testomonies.php)");

 

to:

 

$testimony = ($_SERVER['DOCUMENT_ROOT']."/page/testimony/customer_testomonies.php");

 

and changing:

 

<?php $testimony ?>

 

to:

 

<?php include($testimony); ?>

 

Doing that just gives me these errors:

Warning: include() [function.include]: Filename cannot be empty in C:\Server\www\myserver.dev\vhost\AquaDrilling\public\inc\body\footer.php on line 16

 

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\Server\www\myserver.dev\vhost\AquaDrilling\public\inc\body\footer.php on line 16

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.