note 96723 deleted from regexp.reference.circudollar by danbrown
| From: | danbrown@php.net | Date: | Tue, 10 Aug 2010 15:07:27 +0000 |
| Subject: | note 96723 deleted from regexp.reference.circudollar by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171530@lists.php.net to get a copy of this message | ||
Note Submitter: Robin
----
Two simple examples of how to use ^ and $:
<?php
$hostname = 'www.php.net';
// remove www subdomain from a hostname
echo preg_replace( '/^www[.]/i', '', $hostname ) . PHP_EOL; // output:
php.net
// remove tld from a hostname
echo preg_replace( '/[.].{2,4}$/i', '', $hostname ) . PHP_EOL; // output:
www.php
?>