You are here: Re: can't use include file with php tags « All PHP « IT news, forums, messages
Re: can't use include file with php tags

Posted by Johnny on 08/27/06 06:50

"Mike Collins" <webspammer_@_yaho-o_.com> wrote in message
news:lh02f2pols7o7t99pp4kdihj4lsj2t4rcf@4ax.com...
> While attempting to assign the array elements of an include file to a
> variable the php tags embedded in the include file fail to
> interpolate. What am I missing?
>
> $t_file = file($PATH_DOCS . '/inc/navElem.inc.php');
> $iw_mast .= $t_file[0];
>
> undesired output:
> <ul><li><a href="<?php echo $absPath; ?>/<?php echo $p0_file;
> ?>.php"><?php echo $p0_label; ?></a></li></ul>
>
> would like to get:
> <ul><li><a href="localhost/filename.php">link text</a></li></ul>
>
> Thank you.
looks like it should work but....
PHP inserts variable values as it creates strings so all the values are
already in the string as soon as it is created.
What you have is just a string. When it is output it's too late to get the
values.

One way I found of getting around that for you
is to use the eval function http://us2.php.net/manual/en/function.eval.php
so:

// file 'ftst.php' contents(just one line for testing):
echo "<ul><li><a href=\"$absPath/$p0_file.php\">$p0_label</a></li></ul>";

// script contents to display these using variables defined in the script:
<?php
$absPath = 'localhost';
$p0_file = 'filename';
$p0_label = 'link text';

$t_file = file('ftst.php');
echo eval($t_file[0]);
?>


so you'll need to put echo at the beginning of each line and quote each
line which means you'll also need to escape quotes within the line.
If you read the eval doc on php.net there's several other ways and examples
of similar things.

hth :-)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация