Re: can't use include file with php tags




"Mike Collins" <webspammer_@xxxxxxxxxxxx> wrote in message
news:lh02f2pols7o7t99pp4kdihj4lsj2t4rcf@xxxxxxxxxx
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 :-)



.



Relevant Pages

  • Re: Object of class Person could not be converted to string
    ... PHP has been lousy at maintaining backward compatibility. ... Objects are always converted to the string "Object". ... there's no reasonable gain in usability by forcing it ...
    (comp.lang.php)
  • HOW TO: eval() into a string
    ... evaluate a string with embedded php into a string.) ... PHP Functions as Wiki-isms ... embedded PHP functions that generate strings into a string of pure ... Then we can capture what is in the output buffer ...
    (alt.php)
  • Re: Object of class Person could not be converted to string
    ... PHP has been lousy at maintaining backward compatibility. ... They wouldn't have if the language had been better planned from the start. ... Objects are always converted to the string "Object". ...
    (comp.lang.php)
  • Re: Wordpress Port
    ... database stuff in PHP ... I'm passing a number in as a string. ... achieved the dubious distinction of being the first language I actually ...
    (comp.lang.ruby)
  • Re: Object of class Person could not be converted to string
    ... Objects are always converted to the string "Object". ... But it's not unusual for doc to lag the actual code changes, - in PHP or any other product. ... typed language any more. ...
    (comp.lang.php)