2

I have an email address format like this - [email protected] what i want to do is extract the ID part of this email like this - st15103 How can i do this using PHP string function ?

asela daskon
  • 496
  • 1
  • 8
  • 21
  • 1
    This website is not a code writing service. Please research your problem and post what you have tried including any errors. – user4317867 Dec 25 '15 at 17:29
  • Hello user4317867, i don't know what's your problem. I know that. i'm asking the question because i don't know the solution for it. suddenly i found the solution that's why i posted my finding to the audience. – asela daskon Dec 25 '15 at 18:43
  • I don't have a problem, this website exists for answering errors in programming/scripting. Not a place to ask "I need to do X" without showing any research effort or code sample of what was tried. Key point being effort. I found a duplicate question [here](http://stackoverflow.com/questions/5941832/php-using-regex-to-get-substring-of-a-string) – user4317867 Dec 25 '15 at 18:50

2 Answers2

3

Just split on @ and get the first part ?

$id = array_shift( explode("@", " - [email protected]") );
adeneo
  • 312,895
  • 29
  • 395
  • 388
2

It's Simple explode it.

<?php
$id = explode('@',[email protected])[0];
echo $id;
?>

Hope this helps you

Utkarsh Dixit
  • 4,267
  • 3
  • 15
  • 38