The lan ip address function obtained by PHP is not very useful. Which of the following experts can help you optimize it?

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.