Jump to content

What Does @ in preg_match()


HungryMind

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...