...

View Full Version : PHP FlatFile



Erindesign
10-27-2006, 11:05 PM
I've got this clip of php code which doesn't work... I can't figure out why.

It is supposed to get info from file, and echo it. It should be something like this
<a href="mvid.php?url=emri">ID</a>

my info.txt


emri||ID
emri||ID
emri||ID
emri||ID
emri||ID
emri||ID


my php


$dir = 'Muzik/' . $_GET['artist'];
$Lines = file($dir."/info.txt");
foreach($Lines as $Key => $Val)
{
$video[$Key] = explode("||", $Val);
}
Video Klipi 1: <a href=\"mvid.php?url=$video[0][1]\">$video[0][0]</a><br />
Video Klipi 2: <a href=\"mvid.php?url=$video[1][1]\">$video[1][0]</a><br />
Video Klipi 3: <a href=\"mvid.php?url=$video[2][1]\">$video[2][0]</a><br />
Video Klipi 4: <a href=\"mvid.php?url=$video[3][1]\">$video[3][0]</a><br />
Video Klipi 5: <a href=\"mvid.php?url=$video[4][1]\">$video[4][0]</a><br />
Video Klipi 6: <a href=\"mvid.php?url=$video[5][1]\">$video[5][0]</a><br />


the $video doesn't work. GIves me soething like Array[0] as the link display and Array[1] as the url.

Brandoe85
10-27-2006, 11:37 PM
That looks like it would give you the correct link, what do you get when you do:
echo '<pre>';
print_r($video);
echo '</pre>';

Erindesign
10-27-2006, 11:42 PM
I get nothing but when looked as html (view source) I get:
"<pre></pre>".

Brandoe85
10-27-2006, 11:52 PM
Is the filename and path correct?

Try adding this right before the foreach:
echo '<pre>';
print_r($Lines);
echo '</pre>';

Erindesign
10-28-2006, 12:06 AM
I think my problem is on the foreach because I tried:
$video = explode("||", $Lines[0]);

and it worked fine, for the first item.

anyway, print_r($Line) gave me:
Array
(
[0] => emri1||ID1

[1] => emri2||ID2

[2] => emri3||ID3

[3] => emri4||ID4

[4] => emri5||ID5

[5] => emri6||ID6
)

Brandoe85
10-28-2006, 12:20 AM
Try declaring $video before the foreach, maybe we have a scope issue:
$video = array();

good luck;

CFMaBiSmAd
10-28-2006, 12:29 AM
You are probably echoing these in double-quotes? To get array elements with brackets [...] to be parsed correctly, you need to enclose the array variable in curly-brackets {}. The following will fix this -

echo "
Video Klipi 1: <a href=\"mvid.php?url={$video[0][1]}\">{$video[0][0]}</a><br />
Video Klipi 2: <a href=\"mvid.php?url={$video[1][1]}\">{$video[1][0]}</a><br />
Video Klipi 3: <a href=\"mvid.php?url={$video[2][1]}\">{$video[2][0]}</a><br />
Video Klipi 4: <a href=\"mvid.php?url={$video[3][1]}\">{$video[3][0]}</a><br />
Video Klipi 5: <a href=\"mvid.php?url={$video[4][1]}\">{$video[4][0]}</a><br />
Video Klipi 6: <a href=\"mvid.php?url={$video[5][1]}\">{$video[5][0]}</a><br />";

Erindesign
10-28-2006, 12:32 AM
I fixed it. Stupid curly brackets. I had mixed in info from other arrays as well. slipped out.

By the way, I have a loop to echo all the info. I just typed it out to see if it would work this way and if I had a problem in the array itself or myloops.

Thanks CFMABI

Thanks Brandoe for trying. ;)

Brandoe85
10-28-2006, 12:33 AM
You are probably echoing these in double-quotes? To get array elements with brackets [...] to be parsed correctly, you need to enclose the array variable in curly-brackets {}. The following will fix this -

echo "
Video Klipi 1: <a href=\"mvid.php?url={$video[0][1]}\">{$video[0][0]}</a><br />
Video Klipi 2: <a href=\"mvid.php?url={$video[1][1]}\">{$video[1][0]}</a><br />
Video Klipi 3: <a href=\"mvid.php?url={$video[2][1]}\">{$video[2][0]}</a><br />
Video Klipi 4: <a href=\"mvid.php?url={$video[3][1]}\">{$video[3][0]}</a><br />
Video Klipi 5: <a href=\"mvid.php?url={$video[4][1]}\">{$video[4][0]}</a><br />
Video Klipi 6: <a href=\"mvid.php?url={$video[5][1]}\">{$video[5][0]}</a><br />";
aye, but what gets me is print_r($video) is empty...

CFMaBiSmAd
10-28-2006, 12:34 AM
I posted additional info above, probably while you were typing your last post.

Edit: We don't know at what point in the code he put the print_r($video)... Also it could have contained a typo.. and printed a non-existant variable...

Erindesign
10-28-2006, 12:38 AM
I put the loop in the same loop I use to echo information. But I got it,thanks ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum