Bir Linux makine üzerinde şu anda yapılandırılmış ağ arayüzleri sadece isimlerini almaya çalışırken dize biçimlendirme ile bir sorunla karşılaşmış değilim.
1. <?php
2. $temp = shell_exec("/sbin/ifconfig | cut -b 1-10");
3. echo $temp; //Outputs: eth0 lo
4. $arr = explode(" ",$temp);
5. echo "First Location:".$arr[0]; //Outputs: eth0
6. echo "Second Location:".$arr[1]; //Outputs:
7. echo count($a); //Outputs: 165
8. ?>
How can i get $arr of size=2 such that echo $arr[0]; //gives 'eth0' echo $arr[1]; //gives 'lo'
Thanks a lot
Update: I thing following command will do the magic for me
ifconfig | grep -o -e "[a-z][a-z]*[0-9]*[ ]*Link" | perl -pe "s|^([a-z]*[0-9]*)[ ]*Link|\1|"
Tarayıcı şey görünmüyor çünkü bir php dosyasından yürütülürken ama yanlış bir şey yapıyorum.
<?php
$temp = shell_exec("ifconfig | grep -o -e \"[a-z][a-z]*[0-9]*[ ]*Link\" | perl -pe \"s|^([a-z]*[0-9]*)[ ]*Link|\\1|\"");
echo $temp;
?>