Quick actions

cmd+k|ctrl+k

Navigation

Languages

test_preg_match

Snippet info

Language

Php

Visibility

public

Author

fenghestudio

Created

2019-09-19T04:10:08Z

Updated

2019-09-19T04:10:08Z

<?php

//从URL中获取主机名称
preg_match('@^(?:http://)?([^/]+)@i',
    "http://www.php.net/index.html", $matches);

$host = $matches[1];

//获取主机名称的后面两部分
preg_match('/[^.]+\.[^.]+$/', $host, $matches);

echo "domain name is: {$matches[0]}\n";

?>
INFO