Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract from a text file and convert to variables or array

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I have a text file is formatted like this:

-----------------------------
First text # second text # third text
-----------------------------

how can i read the file and asign i.e:

$one = "First text ";
$tow = "second text";
etc….
or create an array like:
$myarray = " First text , second text , third text";

Thanks in advance
 
The explode function is what you want. However, it will only create a numerically keyed array. If you want an associative array you need a different way.

Also:
When you store each value on it's own line you can use file() to read each line into it's own element. Then no conversion is necessary.
This will only work if there are no elelemnts that contain newline characters. The new array also will contain the newline character as the last char in the element.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top