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
https://forums.phpfreaks.com/topic/193612-making-a-variable-php-code/
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')")

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)")

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

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.

 

 

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.

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); ?>

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

Doing that just gives me these errors:

Yes, did you read them, because they tell you what the problem is. The filename (in $testimony) is empty. Wherever you are defining $testimony at is not in the same program scope as the php code that is using $testimony.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.