i need some code that will take an email address and save everything preceeding the "@" as a variable. example: pete@myactingagent.com becomes "pete". i'm trying to figure it out with the wrox book but i'm stuck. thanks.
substr & strpos are your friends here:
$var=substr($email,0,strpos($email,'@')-1);
Stef has the correct answer for your application but if you decide that you want to keep the domain aswell you can use:
$email = explode("@","pete@myactingagent.com");
$email[0] is then = pete and $email[1] is then = myactingagent.com
thanks a million. $var=substr($email,0,strpos($email,'@')-1); this code actually gets rid of the char immediately preceeding the "@" so i simply dropped the "-1" and it works like a charm. enjoy the good karma you've created for yourself. pete
there's various ways to do it, but if you like regexp <? $email="some@email.com"; ereg("([@])@(.)",$email,$arg); echo "name = $arg[1]; domain = $arg[2]"; ?>
or <? list($name,$domain)=split("@",email); ?>