I am trying to trim a string in PHP so that I can only get certain text from the String.
I have an email stored to a String for instance [email protected] .
How can I remove the text after the '@' so that I would only 'some_name'?
I am trying to trim a string in PHP so that I can only get certain text from the String.
I have an email stored to a String for instance [email protected] .
How can I remove the text after the '@' so that I would only 'some_name'?
In PHP you can do :
$string = '[email protected]';
$res = explode('@', $string);
echo $res[0];
Or you can use regexp, string functions in php ... etc
$name = $res[0]; echo $name;You should know both ways to do this:
$mail = "[email protected]";
echo substr($mail, 0, strpos($mail, '@') );
list($name, $domain) = explode('@', $mail);
echo $name;
If you don't need the $domain you can skip it:
list($name) = explode('@', $mail);
More about list.
Demo: http://ideone.com/lbvQF
$str = '[email protected]';
$strpos = strpos($str, "@");
echo $email = substr($str, 0,$strpos);
you can try this to get string before @
You could try split using regex and the @ symbol. This will return two Strings which you can then use just to acquire the 'some_name'.
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html