我的端口也是[2401:2401:2401:2401:2401:2401:2401:2401]:1234
的IPv6地址。我想只在PHP中获取IPv6地址。我想做的是:
$str = "[2401:2401:2401:2401:2401:2401:2401:2401]:1234";
preg_match("[]", $str, $matches);
echo $matches[1];
但这并没有让我得到正确的结果。
我希望matches[1]
仅包含"2401:2401:2401:2401:2401:2401:2401:2401"
。
答案 0 :(得分:1)
您使用的preg_match
无法正常工作。你需要这样的东西:
preg_match("/\[([0-9a-fA-F:]+)\]/", $str, $matches);