如何从'@'开始删除字符串?如何提取字符串中'@'字符前面的所有文本
例如[email protected],我想删除从@开始的字符串,所以它只能成为'admin'。 就像在twitter ..我读了关于str替换和修剪,但我认为theres其他方式来做到这一点?
$email = '[email protected]';
echo substr_replace($email, ?, ?) ; this i cant do
如何从'@'开始删除字符串?如何提取字符串中'@'字符前面的所有文本
例如[email protected],我想删除从@开始的字符串,所以它只能成为'admin'。 就像在twitter ..我读了关于str替换和修剪,但我认为theres其他方式来做到这一点?
$email = '[email protected]';
echo substr_replace($email, ?, ?) ; this i cant do
你并不需要更换余,你可以切出,直到搜索字符。在这种情况下,它很容易与strtok:
$name = strtok($email, "@");
试试这个功能:strstr:
$start = strstr($email, '@', true);
$email = '[email protected]';
$aEmail= explode('@',$email);
echo $aEmail[0];
什么:
substr($email, 0, strpos($email, '@'));
strtok()
是最好的,但作为一个改变原生...
$name = strstr($email, '@', TRUE);
$email = '[email protected]';
list($Lastpart,$Firstpart) = explode("@",$email);
echo $Firstpart; //before @ sign
echo $Lastpart; //after @ sign
谢谢!非常快 – 2011-06-08 02:53:37