ted_chou12 Posted December 17, 2006 Share Posted December 17, 2006 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"> </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> <a href="../users/"><img src="pm.gif" height="30" width="30" alt="Send Private Message!"></a> <a href="../users/profiles.php?id=' . $usernamee . '"><img src="pf.gif" height="30" width="30" alt="See Profile"></a> <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 thisthanksTed. Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/ Share on other sites More sharing options...
moshdj2uk Posted December 17, 2006 Share Posted December 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/#findComment-143053 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 change it to the one above would source it directly to the text file, but my img src is in the text file, what should i do? Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/#findComment-143058 Share on other sites More sharing options...
moshdj2uk Posted December 17, 2006 Share Posted December 17, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/#findComment-143060 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 hey, thanks mate. it works fine now!!but one question.before Ken taught me this, I used to store the files like this<img src="<? include(display.txt)?>">and it actually worked, why is that??? Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/#findComment-143063 Share on other sites More sharing options...
moshdj2uk Posted December 17, 2006 Share Posted December 17, 2006 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"> </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> <a href="../users/"><img src="pm.gif" height="30" width="30" alt="Send Private Message!"></a> <a href="../users/profiles.php?id=' . $usernamee . '"><img src="pf.gif" height="30" width="30" alt="See Profile"></a> <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. :) Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/#findComment-143066 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 yeap, i am so happy about it too!!Thanks for the teaching as well. :D Quote Link to comment https://forums.phpfreaks.com/topic/31000-solved-combining-the-quotdotquot-and-the-include-function/#findComment-143079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.