Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: php split

  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    1
    Thanked 0 Times in 0 Posts

    php split

    Hey Guys

    I would like to split an email address with PHP, for example.

    mail@anemailaddress.com
    james@anemailaddress.com
    chris@anemailaddress.com

    With the PHP I want to get a list:
    mail
    james
    chris

    I would like to get rid of the email extention.


    PHP Code:
    <?

    echo "$namebefore@";

    ?>
    Many thanks

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You can use explode or a regex.

    Good luck;

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    Use the explode() function:

    PHP Code:
    $email 'mail@anemailaddress.com';
    $email_parts explode('@',$email);
    echo 
    $email_parts[0]; 
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you use the list function then you won't have to deal with the array.
    like this
    PHP Code:
    $email 'mail@anemailaddress.com';
    list(
    $name,$extention) = explode('@',$email);
    print 
    $name


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •