How PHP intercepts the characters before commas

Source: Internet
Author: User
Aaaaa,bbbbbbb,ccccc
First determine if there is a comma (do not know if this step is required, because there is no comma in the case), if there is a truncation of the first comma before the character (without inclusion of commas)


Reply to discussion (solution)

$email = ' name@example.com ';
$domain = Strstr ($email, ' @ ');
Echo $domain; Print @example. com

$user = Strstr ($email, ' @ ', true); From PHP 5.3.0 onwards
Echo $user; Print Name

$str = ' AAAAA,BBBBBBB,CCCCC ', if (Strpos ($str, ', ')) {Preg_match ('/([^,]+?),/I ', $str, $match);} Print_r ($match [1]);/*aaaaa*/

$s = ' AAAAA,BBBBBBB,CCCCC '; Echo strtok ($s, ', ');

$string = ' 111a,111 ';            $flag = Strpos ($string, ', ');            if ($flag!== FALSE) {                $arr = explode (', ', $string);                echo $arr [0];            } else{                echo $string;            }
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.