: This article mainly introduces the function for PHP to obtain the lan ip address, which is not very easy to use? which of the following experts can help optimize the function? if you are interested in the PHP Tutorial, please refer to it. The original code I wrote is as follows:
Function the_lan_ip (){//
If (! Is_windows_ OS () {// if it is not a windows operating system, execute ifconfig to catch the corresponding IPv4 IP address
Exec ('ifconfig', $ output );
For ($ I = 0; $ I <= count ($ output); $ I ++ ){
Error_reporting (0 );
Preg_match ('/\ inet. *:(. *) \ 040/', $ output [$ I], $ the_ip_str); // use regular expressions to find the corresponding IP address of inet, which is the IP address of the LAN.
If (count ($ the_ip_str)> 0 ){
$ The_lan_ip [$ I] = $ the_ip_str [1];
}
}
} Else {exec ('ipconfig', $ output); // if it is a windows operating system, run ipconfig to catch the corresponding IPv4 IP address
For ($ I = 0; $ I <= count ($ output); $ I ++ ){
Error_reporting (0 );
Preg_match ('/\ IPv4. * :(. *)/', $ output [$ I], $ the_ip_str); // use regular expressions to find the IP address corresponding to IPv4, which is the IP address of the LAN.
If (count ($ the_ip_str)> 0 ){
$ The_lan_ip [$ I] = $ the_ip_str [1];
}
}
}
Return ($ the_lan_ip );
}
The above describes the function for PHP to get the lan ip address. it is not very useful. Which of the following experts helped to optimize the function, including some content? I hope my friends who are interested in the PHP Tutorial will be helpful.