note 103141 added to function.strchr
| From: | Eliyahu at EliSko dot com | Date: | Mon, 28 Mar 2011 20:50:09 +0000 |
| Subject: | note 103141 added to function.strchr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178278@lists.php.net to get a copy of this message | ||
Building on Joao's example, here are one-liners for extracting either the user or domain
portions of an email address, without the at-sign:
TO GET THE USER:
(i.e., to extract 'user' from 'user@example.com')
<?php
$user = strrev( substr( strchr( strrev($email), '@'), 1) );
?>
TO GET THE DOMAIN:
(i.e., to extract 'example.com' from 'user@example.com')
<?php
$domain = substr( strchr($email, '@'), 1);
?>
Of course, running <?php strchr() ?> twice is costly, so if you need both halves at once, use
<?php explode() ?> instead.
TO GET BOTH AT ONCE:
<?php
list( $user, $domain ) = explode( '@', $email );
?>
----
Server IP: 212.150.176.150
Probable Submitter: 81.218.215.93
----
Manual Page -- http://www.php.net/manual/en/function.strchr.php
Edit -- https://master.php.net/note/edit/103141
Del: integrated -- https://master.php.net/note/delete/103141/integrated
Del: useless -- https://master.php.net/note/delete/103141/useless
Del: bad code -- https://master.php.net/note/delete/103141/bad+code
Del: spam -- https://master.php.net/note/delete/103141/spam
Del: non-english -- https://master.php.net/note/delete/103141/non-english
Del: in docs -- https://master.php.net/note/delete/103141/in+docs
Del: other reasons-- https://master.php.net/note/delete/103141
Reject -- https://master.php.net/note/reject/103141
Search -- https://master.php.net/manage/user-notes.php