In PHP, a string such as "xxx_xxxx_10.136.132.61_xxxxxxxx_xxxxxx", How to get the "10.136.132.61" part of it.
Because the IP address is different in length, so I think at the beginning of the substr is not applicable. If you look for "_" position, because there are two "_" before and after the IP, so also not.
In addition to the IP address length is not determined, the other length is determined, the format is also determined, are "XXX_XXXX_IP address _xxxxxxxx_xxxxxx" This format, X represents a character
Thank you all for your help!
Reply content:
In PHP, a string such as "xxx_xxxx_10.136.132.61_xxxxxxxx_xxxxxx", How to get the "10.136.132.61" part of it.
Because the IP address is different in length, so I think at the beginning of the substr is not applicable. If you look for "_" position, because there are two "_" before and after the IP, so also not.
In addition to the IP address length is not determined, the other length is determined, the format is also determined, are "XXX_XXXX_IP address _xxxxxxxx_xxxxxx" This format, X represents a character
Thank you all for your help!
If you can determine that other strings do not have the class IP format, you can match
$str = 'xxx_xxxx_10.136.132.61_xxxxxxxx_xxxxxx';$patten = '(/25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}/';preg_match($patten,$str,$result);var_dump($result);$ip = $result[0];
Do not understand PHP, but this question can be answered next, one, the regular match. Two, cut the string, cut the tail.
Use the regular bar.
$data = 'xxx_xxxx_10.136.132.61_xxxxxxxx_xxxxxx';$preg = '/[\d\.]+/i';preg_match($preg, $data, $matches);var_dump($matches);
Explode function is done.
$str = 'xxx_xxxx_10.136.132.61_xxxxxxxx_xxxxxx';$arr = explode('_', $str);print_r($arr);
I ask myself to answer, can use substr ($STR, 9,-16)
explode('_', $str)[2]
With the regular can be very flexible, and with explode, or substr, are opportunistic. 3L is the positive solution
Support explode, simple and convenient, anyway format is fixed