HungryMind Posted July 19, 2011 Share Posted July 19, 2011 Can anyone please tell me that! What "@" are doing in this code? <?php// get host name from URLpreg_match('@^(?:http://)?([^/]+)@i', "http://www.php.net/index.html", $matches);$host = $matches[1];// get last two segments of host namepreg_match('/[^.]+\.[^.]+$/', $host, $matches);echo "domain name is: {$matches[0]}\n";?> Link to comment Share on other sites More sharing options...
jeffman Posted July 19, 2011 Share Posted July 19, 2011 A traditional regex uses /.../ characters to delimit the start and finish of the regex. Many languages support the use of other delimiters. This author has chosen to use & characters, probably because the expression contains a lot of / characters that would have to be escaped, making it hard to read and debug. Link to comment Share on other sites More sharing options...
HungryMind Posted July 19, 2011 Author Share Posted July 19, 2011 Thanks for reply my friend.Can you please re-script this code as simple as possible using preg_match? <?php// get host name from URLpreg_match('@^(?:http://)?([^/]+)@i', "http://www.php.net/index.html", $matches);$host = $matches[1];// get last two segments of host namepreg_match('/[^.]+\.[^.]+$/', $host, $matches);echo "domain name is: {$matches[0]}\n";?> Link to comment Share on other sites More sharing options...
justsomeguy Posted July 19, 2011 Share Posted July 19, 2011 Unless you want to change the pattern and look for something else, that's about as simple as it gets. There's an easier way to get the host from a URL though.http://www.php.net/manual/en/function.parse-url.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.