From c46aa354dcffecd6ba56a058e3ced2f07bfec7e9 Mon Sep 17 00:00:00 2001 From: Monte Ohrt Date: Thu, 5 Oct 2000 16:40:11 +0000 Subject: [PATCH] fix example three git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@33413 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/pcre.xml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/functions/pcre.xml b/functions/pcre.xml index c04ec0b232..6cd2fc909b 100644 --- a/functions/pcre.xml +++ b/functions/pcre.xml @@ -120,10 +120,13 @@ if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice." Getting the domain name out of a URL -preg_match("/^(.*)([^\.]+\.[^\.]+)(\/.*)?/U", - "http://www.php.net/index.html", $matches); -// show the second parenthesized subpattern -echo "domain name is: ".$matches[2]."\n"; +// get host name from URL +preg_match("/^(http:\/\/)?([^\/]+)/i", +"http://www.php.net/index.html", $matches); +$host = $matches[2]; +// get last two segments of host name +preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$matches); +echo "domain name is: ".$matches[0]."\n"; This example will produce: