Re: can't use include file with php tags




"Mike Collins" <webspammer_@xxxxxxxxxxxx> wrote in message
news:a513f29kmupbv3q6h0cjobvu7fpcjfhsbv@xxxxxxxxxx
On Sat, 26 Aug 2006 23:50:05 -0700, "Johnny"
<removethis.huuanito@xxxxxxxxxxx> wrote:

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];

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.

echo, quote, escape, rtm... right. I went round and round with this
for awhile. Almost gave up. Here's what I'm using:

ob_start();
include($PATH_DOCS . '/inc/navElem.inc.php');
$iw_mast .= ob_get_contents();
ob_end_clean();

That works for one line but I don't see how it fills your need to populate
an array, but maybe you don't need to.

BTW I wasn't saying RTFM in the previous post, I was trying to point you to
other approaches that were best described by links to TM.
TM for php is very good, IMO, way better than other languages, with lots of
support from other users as well as the core team.

So using include() I've found, though it's not explicitly stated, you need
php tags at the start and end of any php you have in a file and if there's
none then you need to escape php by opening and closing php at the start.
This is because php expects php code in an include file. For me this works
as I can construct a page using several includes for like header body and
footer (when not using classes for the same).

What you have now done seems equivalent to doing this (adding php tags to
start of the include file):

------------ftst.php --------------
<?php // file ftst.php ?>
<ul><li><a href="<?php echo $absPath; ?>/<?php echo $p0_file;?>.php"><?php
echo $p0_label; ?></a></li></ul><?php ?>
---------------------------------

------------f.php --------------
<?php // file f.php
$absPath = 'localhost';
$p0_file = 'filename';
$p0_label = 'link text';

include ("ftst.php");
?>
---------------------------------


So when you run f.php it puts the link correctly and if you expand to
several lines (with extra vars $p1_file, etc.) that works too.
The plain include seems a whole lot simpler to me than the whole ob_ thing
but YMMV, depends what you are trying to do.

I use include files all the time with php tags in them and never have
problems, but then I usually escape out of php as shown.
The heredoc syntax can also help with reducing all those "<?php echo ... ?>
constructs and no need to escape quotes, also single quotes around a string
can work sometimes.
for example you could use this as the include file:

----------------ftst.php---------
<?php // ftst.php
echo <<<LINKS
<ul>
<li><a href="$absPath/$p0_file.php">$p0_label</a></li>
<li><a href="$absPath/$p1_file.php">$p1_label</a></li>
<li><a href="$absPath/$p2_file.php">$p2_label</a></li>
<li><a href="$absPath/$p3_file.php">$p3_label</a></li>
</ul>
LINKS;
?>
----------------------------------

This makes things much simpler... f.php just needs to define all those
extra vars:

------------f.php --------------
<?php // file f.php

$absPath = 'localhost';
$p0_file = 'filename0';
$p0_label = 'link0 text';
$p1_file = 'filename1';
$p1_label = 'link1 text';
$p2_file = 'filename2';
$p2_label = 'link2 text';
$p3_file = 'filename3';
$p3_label = 'lin3 text';

include ("ftst.php");
?>
---------------------------------

/* johnny */


.



Relevant Pages

  • Re: COM - ADSI & PHP
    ... I keep running into a problem is with a specific OU that has braces ... I know that the LDAP functions in PHP may be able to help but the ... Also, note that in PHP, '\' is an escape character - if you're using ... Did you escape the characters with a backslash, or did you use the hex equivalent? ...
    (alt.php)
  • Re: COM - ADSI & PHP
    ... I keep running into a problem is with a specific OU that has braces ... I know that the LDAP functions in PHP may be able to help but the ... Also, note that in PHP, '\' is an escape character - if you're using ... Yah I have tried that by building a function to escape the characters ...
    (alt.php)
  • RE: [PHP] preg_match problem
    ... Subject: [PHP] preg_match problem ... Pattern Syntax -- Describes PCRE regex syntax ... backslash character rather than using backslash to escape ...
    (php.general)
  • Re: [PHP] Slashes, include, AJAX? {SOLVED}
    ... how are you using the json object on the client-side after its sent by the server? ... ive have not encountered the problem you have, that is, the escape characters do ... im using the same encoding technique i recommended within PHP. ... if you use a string directly on the client side, ...
    (php.general)
  • Re: COM - ADSI & PHP
    ... I keep running into a problem is with a specific OU that has braces ... I know that the LDAP functions in PHP may be able to help but the ... Also, note that in PHP, '\' is an escape character - if you're using double quotes, you need to also double it up before passing, i.e. ...
    (alt.php)