3

I want to get the first bit of the string after the occurrence of the needle like this...

$user = strstr('someemail@yahoo.com', '@', true); 

But this only works with PHP Version 5.3.0, I have 5.2.9 Is there a way I can get the same results?

InvalidSyntax
  • 9,131
  • 20
  • 80
  • 127

1 Answers1

9
list($user, $therest) = explode('@',$email);
dnagirl
  • 20,196
  • 13
  • 80
  • 123
  • 1
    I was going to suggest `strpos` with `strstr`, but then I saw how much this answer was *already* putting my suggestion to shame. – Carson Myers Oct 05 '09 at 19:40
  • Nice answer, Can you still acess the username with $user? or does this store it in a list? – Stephan Jul 29 '13 at 17:55