Home > Backend Development > PHP Tutorial > PHP 截取邮箱URL 方法.求解!该怎么处理

PHP 截取邮箱URL 方法.求解!该怎么处理

WBOY
Release: 2016-06-13 13:29:25
Original
876 people have browsed it

PHP 截取邮箱URL 方法...求解!
如题:想截取邮箱 @符 到 .com 之间的数据,本人菜鸟求帮助!
例:123456@163.com 截取之后变成 163 即可。

------解决方案--------------------
preg_match('/@(\w+)\.com/',$s,$m);
echo $m[1];
------解决方案--------------------
substr($mail, strpos('@')+1,strrpos('.'));
------解决方案--------------------
strpos 看这个方法的参数
------解决方案--------------------
$aa = substr($mail,strpos($mail, '@')+1,strrpos($mail, '.'));

#1 的正则不好吗?
------解决方案--------------------

探讨

$aa = substr($mail,strpos($mail, '@')+1,strrpos($mail, '.'));

#1 的正则不好吗?

------解决方案--------------------
C/C++ code
[User:root Time:08:51:06 Path:/home/liangdong/php]$ php preg.php 
163
[User:root Time:08:51:07 Path:/home/liangdong/php]$ cat preg.php 
<?php $str = <<<EOF
123456@163.com
EOF;
$nmatches = preg_match('/^[\d\w]+@([\d\w]+)\.com$/iU', $str, $matches);
if ($nmatches) {
        echo $matches[1]. PHP_EOL;
}
?> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template