Jump to content

Writing array to a file


devWhiz

Recommended Posts


<?php
$file = 'test.txt';
$lastfm = file_get_contents('http://www.last.fm/group/Rishloo/members');
preg_match_all('/id="r4_([\d]+)">/', $lastfm, $matches);
file_put_contents($file, $matches[1]);


sleep(100000);

?>

 

That puts the array in a file but I need each value on a new line but it bunches it all up..

 

this just puts "Array" in file

 

 

<?php

$file = 'test.txt';

$lastfm = file_get_contents('http://www.last.fm/group/Rishloo/members');

preg_match_all('/id="r4_([\d]+)">/', $lastfm, $matches);

file_put_contents($file, $matches[1]."\n");

 

 

sleep(100000);

 

?>

 

what do I need to do to print all of the values on a new line?

 

Thanks

Link to comment
Share on other sites

Wildteen your awesome!! helped me with alot of stuff today..

 

one more question

 

so

file_put_contents($file, implode("\n", "blah".$matches[1]));

writes the matches each on a new line... how would I go about putting something in front of the id like this

 

$ID[] = 1234578;
$ID[] = 1234578;
$ID[] = 1234578;
$ID[] = 1234578;
$ID[] = 1234578;
$ID[] = 1234578;

 

instead of

1234578
1234578
1234578
1234578
1234578

 

Thanks!

Link to comment
Share on other sites

Cant edit above post, but this is the code I have..

 

<?php
$file = 'Lastfm IDs.txt';
$ch = curl_init();
for($cwb=1; $cwb!=399; $cwb++)
{
curl_setopt($ch, CURLOPT_URL, "http://www.last.fm/group/i'm+not+anti-social%2C+i+just+enjoy+my+music./members?memberspage=".$cwb);	
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
preg_match_all('/id="r4_([\d]+)">/', curl_exec($ch), $matches);
file_put_contents($file, implode($matches[1], "\n"), FILE_APPEND);
echo "#".$cwb." pages with user ids loaded...\n";
}
curl_close($ch);
sleep(100000);
?>

 

now,, everytime it does a loop it loads a different members page.., every time it loads a new one and writes the ids from that page.. it looks like this in the id file

 

14423441
32839962
36683385
3670648838089858
11899884
31379239
31517343
14856674

 

when it should be

 

 

14423441
32839962
36683385
36706488
38089858
11899884
31379239
31517343
14856674

 

Thanks for the help man

Link to comment
Share on other sites

shit man so simple! how did I not think of that.. prob cuz I tried it without implode and it just wrote "Array" to the file Lol, thanks man I appreciate it!!

 

And last.fm is a site where people can discover new music based on the music you scrobble on yor computer with the last fm scrobbler, so it records everything you listen to and recommend similar artists to broaden your taste and such in music.. if that makes sense :P

 

well this script loads members pages from group on the site that people put together so people can talk about music and such, well the script loads all of the ids of members in the group.. and writes to a text file..

 

Later on I am going to make a script that will request friendship with that list of ids.. I will have a couple hundred thousand by time Im done :P

 

Thanks for the help, Im sure I will need some help when I go to write the script to add the friends, I usually get stuck where it is always a simple solution.. Lol

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.