eucumata Posted May 25, 2011 Report Posted May 25, 2011 Avem fisierul : fisier.txt care contineBAD: ***.223.80.251:guest:guestBAD: ***.223.81.34:guest:guestOK: ***.202.122.224:guest:guestOK: ***.202.122.228:guest:guestOK: ***.202.122.230:guest:guestOK: ***.202.122.227:guest:guestOK: ***.220.72.1:guest:guestOK: ***.220.196.1:guest:guestOK: ***.221.40.1:guest:guestOK: ***.230.139.35:guest:guestOK: ***.230.161.151:guest:guestBAD: ***.254.40.155:guest:guestAvem scriptul : <?php$ok = file("fisier.txt");foreach ($ok as $nr => $line){$ss = explode(":",$line);$IP = trim($ss[1]);if (!empty($IP))$content = file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key=4e8d48cdc36fb87632873c5c93de9889d2c9454082c03e83dffbb46b34cb3260&ip='.$IP);}print "[iP = $content]"?>Cand execut scriptul.. ar trebui sa imi apara 'Location' de la fiecare ip in parte... dar imi apare doar de la ultimul.[iP = OK;;188.254.40.155;UK;UNITED KINGDOM;-;-;-;54.167;-4.48211;+00:00] Quote
razer_krait Posted May 25, 2011 Report Posted May 25, 2011 Pei ma omule "print "[iP = $content]" e pus in afara foreach-ului . Quote
hammerfall Posted May 25, 2011 Report Posted May 25, 2011 Baga si print-ul in loop. Practic, tu redefinesti $content la fiecare trecere prin loop, dar il afisezi doar dupa ce termini loopingul.Edit: scuze razer, n-am vazut ca ai postat si tu. Quote
eucumata Posted May 25, 2011 Author Report Posted May 25, 2011 (edited) Pei ma omule "print "[iP = $content]" e pus in afara foreach-ului .<?php$ok = file("fisier.txt");foreach ($ok as $nr => $line){$ss = explode(":",$line);$IP = trim($ss[1]);if (!empty($IP))$content = file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key=4e8d48cdc36fb87632873c5c93de9889d2c9454082c03e83dffbb46b34cb3260&ip='.$IP);print "[iP = $content]"}?>[root@localhost ~]# php a.phpPHP Parse error: syntax error, unexpected '}' in /root/a.php on line 9[root@localhost ~]#Da am uitat sa pun ; dupa print ms .. merge... Edited May 25, 2011 by eucumata Quote
razer_krait Posted May 25, 2011 Report Posted May 25, 2011 Dupa faza cu print blablabla n-are trebuie sa pui cumva ";" ? Quote
pr00f Posted May 25, 2011 Report Posted May 25, 2011 La print "[IP = $content]"Nu ai pus ; de sfâr?it. Quote
eucumata Posted May 25, 2011 Author Report Posted May 25, 2011 Dupa faza cu print blablabla n-are trebuie sa pui cumva ";" ?Acum le arata asa [iP = OK;;188.221.176.1;UK;UNITED KINGDOM;ENGLAND;LONDON;-;51.517;-0.105;+00:00][iP = OK;;188.222.88.1;UK;UNITED KINGDOM;-;-;-;54.167;-4.48211;+00:00][iP = OK;;188.223.120.1;UK;UNITED KINGDOM;ENGLAND;MANCHESTER;-;53.483;-2.249;+00:00]cum il fac sa apara pe alt rand ? [iP = OK;;188.221.176.1;UK;UNITED KINGDOM;ENGLAND;LONDON;-;51.517;-0.105;+00:00][iP = OK;;188.222.88.1;UK;UNITED KINGDOM;-;-;-;54.167;-4.48211;+00:00][iP = OK;;188.223.120.1;UK;UNITED KINGDOM;ENGLAND;MANCHESTER;-;53.483;-2.249;+00:00] Quote
razer_krait Posted May 25, 2011 Report Posted May 25, 2011 Pei nenea , la ce-ti trebuie de-astea daca nu stii cu ce se mananca? Trebuie pus vesnicul "/n" care inseamna "new line".print "[IP = $content]/n"; sau echo '/n'; la final Quote
rattrap Posted May 25, 2011 Report Posted May 25, 2011 sau mai bine pui:print "[iP = $content]\n"; 1 Quote
eucumata Posted May 25, 2011 Author Report Posted May 25, 2011 sau mai bine pui: print "[iP = $content]\n"; Perfect , merge, multam.Pei nenea , la ce-ti trebuie de-astea daca nu stii cu ce se mananca?Invat Quote
hammerfall Posted May 25, 2011 Report Posted May 25, 2011 OFF: Lasa ca asa invata mai bine, cand isi da singur pumni in gura ca nu-i iese. Nu din tutoriale unde invata in plictiseala. Quote