Jump to content

php variables


talor123

Recommended Posts

hey, im not realy to good at php, does anyone happen to no a code that does the following:

 

1)gets a files contents(i no how to use 'file_get_contents')

 

this is the bit i do not no how to do:

 

2) the script will read the file and set each line to a numbered variable.. eg:

 

the variable 1 would be set to the first line of text

the variable 2 would be set to the second line of text

and so on...

 

thanx in advanced  :)

Link to comment
https://forums.phpfreaks.com/topic/108340-php-variables/
Share on other sites

2) the script will read the file and set each line to a numbered variable.. eg:

 

the variable 1 would be set to the first line of text

the variable 2 would be set to the second line of text

and so on...

 

thanx in advanced  :)

Note: variables can not start with a number. but it can be done with code some thing like this

$i=0;
# open file
# loop through file.
{$var="varname".$i;
$$var=$line;  # read each line 
$i++;
}

I have use this in the past, but now prefer to use arrays they are much easier to work with later.

# open file
# loop through file.
{
$array_name[]=$line;  # read each line 
}

Link to comment
https://forums.phpfreaks.com/topic/108340-php-variables/#findComment-555708
Share on other sites

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.