How to divide strings into two parts

Source: Internet
Author: User
Divide the string into two parts and divide the string into two strings: $ str & nbsp; = & nbsp; "www.asdfsfd.com, A: xiaohua, www.baidu.com, A: huanghuang, www.360buy.com, www.baihua.com, www. huanghu divides the string into two parts:
Split A string into two strings according to www and:
$ Str = "www.asdfsfd.com, A: xiaohua, www.baidu.com, A: huanghuang, www.360buy.com, www.huahua.com, www.huanghuang.com, A: asdds, www.dd.com "; divide the string into two strings and output them as $ a = "www.asdfsfd.com, www.baidu.com, www.360buy.com, www.baihua.com, www.huanghuang.com, www.dd.com ";
$ B = "A: xiaohua, A: huanghuang, A: asdds"; php, string processing
------ Solution --------------------
Preg_match_all ("/www \. [a-z] * \. [a-z] */is", $ str, $ out );
Preg_match_all ("/A: [a-z] */is", $ str, $ out2 );
------ Solution --------------------
$ Str_arr = explode (',', $ str );
Foreach ($ str_arr as $ key => $ val ){
If (substr ($ val, 0, 3) = 'WWW '){
$ A_str. = $ val .',';
} Else {
$ B _str. = $ val .',';
}
}
$ A = substr ($ a_str, 0,-1 );
$ B = substr ($ B _str, 0,-1 );
------ Solution --------------------
$ Str = "www.asdfsfd.com, A: xiaohua, www.baidu.com, A: huanghuang, www.360buy.com, www.huahua.com, www.huanghuang.com, A: asdds, www.dd.com ";
Preg_match_all ("/(? :( Www \..*?),
------ Solution --------------------
(\:.*?) (? =,
------ Solution --------------------
$)/", $ Str, $ match );
$ Str1 = preg_replace ("/, {2,}/", implode (",", $ match [1]);
Echo preg_replace ("/^,/", "", $ str1 );
Echo"
";
$ Str2 = preg_replace ("/(, {2,})/", implode (",", $ match [2]);
Echo preg_replace ("/^,/", "", $ str2 );

------ Solution --------------------
$str = "www.asdfsfd.com,A:xiaohua,www.baidu.com,A:huanghuang,www.360buy.com,www.huahua.com,www.huanghuang.com,A:asdds,www.dd.com";
preg_match_all('/(www[\w.]+),?(A:\w+)?/',$str,$m);
echo join(',',$m[1]);
echo '
';
echo join(',',array_diff($m[2],array('')));

------ Solution --------------------
$ Str = "www.asdfsfd.com, A: xiaohua, www.baidu.com, A: huanghuang, www.360buy.com, www.huahua.com, www.huanghuang.com, A: asdds, www.dd.com ";

Preg_match_all ('/(www [^,] +)
------ Solution --------------------
(A: [^,] +)/', $ str, $ res );
$ A = join (',', array_diff ($ res [1], array ('')));
$ B = join (',', array_diff ($ res [2], array ('')));

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.