strstr and strpos
啥也不说 直接上代码:
<?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // 打印 @example.com echo '<br>'; $user = strstr($email, '@', true); // 从 PHP 5.3.0 起 echo $user; // 打印 name echo '<br>'; $user = strpos($email, '@'); // 从 PHP 5.3.0 起 echo $user; // 打印 name ?>
看结果:
@example.com
name
4