removing @email.com from string in php

前端 未结 6 1704
感动是毒
感动是毒 2021-01-17 18:00

I want to just get the left half of an email address ( the username part of username@email.com ), so stripping the @ and any characters after it.

6条回答
  •  礼貌的吻别
    2021-01-17 18:31

    If you have PHP5.3 you could use strstr

    $email = 'username@email.com';
    
    $username = strstr($email, '@', true); //"username"
    

    If not, just use the trusty substr

    $username = substr($email, 0, strpos($email, '@'));
    

提交回复
热议问题