Jump to content

[SOLVED] combining the "dot" . and the include function.


ted_chou12

Recommended Posts

This is what Ken taught me today:

[code]
<?php
$diaryarray = file("$include-file.php");
foreach($diaryarray as $v) {
      list($namee,$usernamee,$reply,$datetimee,$comment) = explode("#",$v);
      echo '<table bgcolor="#FAEBD7" width="100%" align=center><tr bgcolor="#EEE8AA">&nbsp;</tr>
<tr><td align=center width="28%" bgcolor="#E0FFFF" valign=top><br><font face="arial" size=4><b>Posted by: ' .$namee . '</b></font><br><br><img src="<?include("../users/' . $usernamee . '/display.txt")?>" height=100><br><br>
<font face="arial" size=4>Posts: <?include("../users/'.$usernamee.'/poster.txt");?></font><br><br>
<a href="../users/' . $usernamee . '/"><img src="hp.gif" height="30" width="30" alt="Personal Page"></a>&nbsp;&nbsp;
<a href="../users/"><img src="pm.gif" height="30" width="30" alt="Send Private Message!"></a>&nbsp;&nbsp;
<a href="../users/profiles.php?id=' . $usernamee . '"><img src="pf.gif" height="30" width="30" alt="See Profile"></a>&nbsp;&nbsp;
<a href="../users/gb.php?id=' . $usernamee . '"><img src="gb.gif" height="30" width="30" alt="Guestbook"></a></td><td valign=top><font face="arial" size=5 color="#666666"><b>' . $reply . '</b></font><br><font face="arial" size=4><b>Posted: ' . $datetimee . '</b><hr>' . $comment . '</font></td></tr></table>' . "\r\n";}
?>
[/code]
can anyone please check between the include and the "dots" . ? I dont think I have done it right, so it doesn't function the echoed php part in the page.
If you dont understand me, just reply to this
thanks
Ted.
you can't use the include funtion in that fashion. You're trying to use PHP, within PHP.

[code]<img src="../users/" . $usernamee . "/display.txt" height="100">[/code]

What you're trying to do though is to read a value from a text file, then include the line as an image. You'll have to grab the content of the .txt file first.
[code]$file = "../users/" . $usernamee . "/display.txt";
$fh = fopen($file, 'r');
$data = fread($fh, filesize($file));
fclose($fh);[/code]

You'd then have $data which you could use like so:

[code]
<img src="'.$data.'" height="100">[/code]
The code you originally posted was:

[code]<?php
$diaryarray = file("$include-file.php");
foreach($diaryarray as $v) {
      list($namee,$usernamee,$reply,$datetimee,$comment) = explode("#",$v);
      echo '<table bgcolor="#FAEBD7" width="100%" align=center><tr bgcolor="#EEE8AA">&nbsp;</tr>
<tr><td align=center width="28%" bgcolor="#E0FFFF" valign=top><br><font face="arial" size=4><b>Posted by: ' .$namee . '</b></font><br><br><img src="<?include("../users/' . $usernamee . '/display.txt")?>" height=100><br><br>
<font face="arial" size=4>Posts: <?include("../users/'.$usernamee.'/poster.txt");?></font><br><br>
<a href="../users/' . $usernamee . '/"><img src="hp.gif" height="30" width="30" alt="Personal Page"></a>&nbsp;&nbsp;
<a href="../users/"><img src="pm.gif" height="30" width="30" alt="Send Private Message!"></a>&nbsp;&nbsp;
<a href="../users/profiles.php?id=' . $usernamee . '"><img src="pf.gif" height="30" width="30" alt="See Profile"></a>&nbsp;&nbsp;
<a href="../users/gb.php?id=' . $usernamee . '"><img src="gb.gif" height="30" width="30" alt="Guestbook"></a></td><td valign=top><font face="arial" size=5 color="#666666"><b>' . $reply . '</b></font><br><font face="arial" size=4><b>Posted: ' . $datetimee . '</b><hr>' . $comment . '</font></td></tr></table>' . "\r\n";}
?>[/code]

That was all in [tt]<?php / ?>[/tt] tags. Within that section of code you had [tt]<?include("../users/' . $usernamee . '/display.txt")?>[/tt]. In essence, you were trying to call PHP, within PHP, which won't work, you'd have to stop the [tt]echo[/tt] statement first, then call the php statement.

If you had called a simple <?include("../users/' . $usernamee . '/display.txt")?> not within an open PHP statement, it would have been fine.

Glad to hear you got it working. :)

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.