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
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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.