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 ('')));