Possible Duplicate:
Text file lines into array with PHP
How can I replace this
$streams = array(
"name1",
"name2",
"name3",
"name4",
"name5",
"name6",
);
with something like
$streams = array(
streams.txt
);
where streams.txt includes
"name1",
"name2",
"name3",
"name4",
"name5",
"name6",
Basically what the whole code does is that it reads from that array those names, and checks on justin.tv if the streams are online. Heres all of the code where I tried to fix it.
<?
$chan = "";
$streams = file('streams.txt');
echo "Live User Streams: ";
foreach ($streams as &$i) {
$chan = "http://api.justin.tv/api/stream/list.json?channel=" . $i;
$json = file_get_contents($chan);
$exist = strpos($json, 'name');
if($exist) {
echo "$i http://twitch.tv/" . $i . " | ";
}
}
echo "";
?>
The file() function seems to be what you want.
$lines = file("streams.txt");
You may have to massage your input text a little, or post-process the lines after they're sucked in to the array.
UPDATE:
Here's a command-line example that works on my workstation:
[ghoti@pc ~]$ cat streams.txt
one
two
three
[ghoti@pc ~]$ php -r '$a = file("streams.txt"); print_r($a);'
Array
(
[0] => one
[1] => two
[2] => three
)
[ghoti@pc ~]$
You need to read the file's content (you can use file_get_content), and then use explode to turn it into an array.