Includes with Strings?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
panoramical
Forum Newbie
Posts: 8
Joined: Mon Dec 27, 2004 6:34 am

Includes with Strings?

Post by panoramical »

To access the file $reverse[] refers to, it's here: http://nindsnet.com/db/home.inc
First problem is that where I first commented, $reverse[1]. This string reads as valid HTML, and it is an img link: <img src etc. etc.... However, the image doesn't display for some reason.
The second problem is that on my second comment, I can't seem to include that file. Why?
The link to my site is here: http://www.nindsnet.com/indexo.php
I'd be grateful for any help.

Code: Select all

$data = file('db/home.inc');
$reverse = array_reverse($data);
echo $reverse&#1111;0];
echo '
    </td>
    </tr>
<tr>
<td bgcolor="#CCCCCC">';
echo $reverse&#1111;1]; //$reverse&#1111;1] is a valid img src link to an existing image...that doesn't display for some reason on the page
$result = include("news/admin/content/$reverse&#1111;2]"); //Doesn't include..?
$result;
Thanks
User avatar
skehoe
Forum Commoner
Posts: 59
Joined: Sun Dec 22, 2002 5:57 am
Location: Denver

Post by skehoe »

You may want to try a print_r statement after the first line in your example to make sure you're getting the home.inc file read in the first place.

~Scott
panoramical
Forum Newbie
Posts: 8
Joined: Mon Dec 27, 2004 6:34 am

Post by panoramical »

I know it's being read, because it's displaying other stuff from the file too...
User avatar
skehoe
Forum Commoner
Posts: 59
Joined: Sun Dec 22, 2002 5:57 am
Location: Denver

Post by skehoe »

Yeah... I was kinda hoping you could post the result of that print_r so that I could see what's in there and maybe be able to help you out.
panoramical
Forum Newbie
Posts: 8
Joined: Mon Dec 27, 2004 6:34 am

Post by panoramical »

sure...sorry.

Code: Select all

Array ( &#1111;0] => View Comments &#1111;1] => nintendodsreleased.inc &#1111;2] => No Avatar  &#1111;3] => Nintendo DS Released (Posted by panoramical on Tuesday 28th of December 2004 01:12:05 AM) )
User avatar
Gonik
Forum Newbie
Posts: 19
Joined: Fri Aug 30, 2002 7:39 am
Location: Somewhere Around Nothing

Post by Gonik »

If the above var dump is the $data one, the reversed should be:

Code: Select all

Array
(
     &#1111;0] =&gt; Nintendo DS Released (Posted by panoramical on Tuesday 28th of December 2004 01:12:05 AM)
     &#1111;1] =&gt; No Avatar
     &#1111;2] =&gt; nintendodsreleased.inc
     &#1111;3] =&gt; View Comments
)
As we can see there is no valid img src link for $reverse[1].
Second, are you absolutely sure that there is actually a file named nintendodsreleased.inc in the exact directory you specified? (news/admin/content/).
Furthermore, try using fopen() for opening the file and not include(). include() should not be used to echo files but just for referencing php code.

Also use

Code: Select all

<? echo $varname; ?>
to display text to the browser. Not just the name of the variable followed by a semicolon.
panoramical
Forum Newbie
Posts: 8
Joined: Mon Dec 27, 2004 6:34 am

Post by panoramical »

Ok, thanks.
I can't see why the image link is not valid, as if you go to the actual database file: http://nindsnet.com/db/home.inc then there is clearly a valid img src link there. The file I want to output also exists. I'll try using fopen.
Post Reply