note 103141 deleted from function.strchr by danbrown

From: Date: Mon, 28 Mar 2011 21:01:54 +0000
Subject: note 103141 deleted from function.strchr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178280@lists.php.net to get a copy of this message
Note Submitter: Eliyahu at EliSko dot com ---- 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 ); ?>

« previous php.notes (#178280) next »