Jump to content

Need help on the explode function


victorianrider

Recommended Posts

Ok so what I have is a list of 32,000 IDs in a separate file called 32kIDs.txt and it has a list of roughly 32,000 user IDs for facebook which look like 100000233850312;1521225383;100000282767638;1252335882;1804268242

 

They're all separated by a semi-colon. What I need this script to do is echo each and every ID on screen, echoing each ID on a new line. I have been using the explode function but having trouble with it since I'm very new to PHP and don't have much experience yet.

 

Here is my current code:

 

<?PHP

$iFile = "32kIDs.txt";

$login = file($iFile, FILE_SKIP_EMPTY_LINES);

if(!is_file($iFile)) echo "The 32k add list couldn't be found...".sleep(999999);

foreach($login as $line_num => $line)

{

$login = explode(" ", htmlspecialchars(str_replace(";"," ",$line)));

echo $login[0]."\n";

}

sleep(20);

?>

 

So I bet there are going to be things in there that I don't even need and thing's I'm missing, if anyone can help it would be much appreciated. And I'd like to keep the code short, I could just put in:

echo $login[0]."\n";

echo $login[1]."\n";

echo $login[2]."\n";

echo $login[3]."\n";

 

all the way up to echo $login[32246]."\n"; but yeah I don't like the thought of a 32k+ line script.

 

Anyways...

Link to comment
https://forums.phpfreaks.com/topic/216476-need-help-on-the-explode-function/
Share on other sites

Presuming there are only numbers and semi-colons...

$string = file_get_contents($filename);
$myarray = explode(";"$string);
$count = count($myarray);
$i=0;
while($i<$count) {
echo $myarray[$i] . "<br>";
$i ++;
}

 

Thankyou so much, worked a treat :)

 

Cheers

Aside from the parse error in the explode line :) litebearers code is a way to do it, however I prefer foreach():

 

$string = file_get_contents($filename);
$logins = explode(";", $string);

foreach($logins as $login) {
   echo $login . "<br>";
}

 

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.