Exploding array values in PHP -


i'm working on script connects server using proxies, going through list until finds working proxy.

the list of proxies this:

127.0.0.1:8080 127.0.0.1:8080 127.0.0.1:8080 127.0.0.1:8080 127.0.0.1:8080 127.0.0.1:8080 127.0.0.1:8080 

of course, it's not same ip , port on , over. now, going use file() put them array, leaves array values including full line, obviously.

ideally i'd array like

"127.0.0.1" => 8080, "127.0.0.1" => 8080, "127.0.0.1" => 8080, "127.0.0.1" => 8080, "127.0.0.1" => 8080, "127.0.0.1" => 8080, "127.0.0.1" => 8080, "127.0.0.1" => 8080, 

but i'm not sure of easiest (and efficient) way that. suggestions?

loop on file , parsing:

$path = './file.txt';  $proxies = array(); foreach(file($path, file_skip_empty_lines) $line) {   $proxy = trim($line);   list($ip, $port) = explode(':', $proxy);    $proxies[$ip] = $port; }  var_dump($proxies); 

should note 'expected' example invalid array notation key same every element. assumed going formatting.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -