Jump to content

Opening a File in php


rotten69

Recommended Posts

Hey all,

 

I'm just having a problem with this code.. the local server says it has an error on a particular line that will be pointed out in the coding section.



<?php
$hd = fopen('content.txt', 'r');
$line = fgets($hd);
$content = array();

while($line)
{
	$word = explode(',', $line);
	$content [$word[0]] => array('img_path' => $word[1], 'description' => $word[2], 'price' => $word[3]); 

// the error message is indicating this line is broken!! Is it because of an equal sign missing? I tried putting an equal sign, but still it doesn't run.

	$line = fgets($hd);
}
fclose($hd);

?>

 

Your help is greatly needed..

Link to comment
https://forums.phpfreaks.com/topic/236172-opening-a-file-in-php/
Share on other sites

This line

<?php
$content [$word[0]] => array('img_path' => $word[1], 'description' => $word[2], 'price' => $word[3]);
?>

is where the error is. You probably want

<?php
$content[$word[0]] = array('img_path' => $word[1], 'description' => $word[2], 'price' => $word[3]);
?>

 

Ken

Thanks, ken.  This solved the problem I had. I tried "=" instead of "=>", then it did not work for me at all.  Just a quick question. I'm interested in programming in PHP, but I still struggle with the logic of it.  What do you think it could help me learn it and master it eventually?

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.