Solutions for intercepting string digits separated by commas

Source: Internet
Author: User
String digits separated by commas, 48. about the number of digits of a string separated by commas
The string edited by liangcaijian at 16:06:09 is: 0, 48423,48425, 48427,48419, 48413,48415, 48213,48418, 48414,48416, 48411,

Note: extract the bold part...

Effects: 48423,48425, 48427,48419

The delimiter is a string separated by commas (,). The delimiter is separated from the first comma (,) to three commas.

How to implement it? Help, online, etc ..
------ Solution --------------------
$s = '0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,';

echo preg_replace('/\d+,((?:\d+,){3}\d+).*/', '$1', $s);

------ Solution --------------------
$string = "0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,";
 $ar=explode(',',$string);
  $arr=array_slice($ar,1,4);
  echo join(',',$arr);

------ Solution --------------------

$ Str = ,";
Function jiequ ($ str, $ a, $ B ){
$ Ar = explode (",", $ str );
For ($ I = $ a; $ I <$ B; $ I ++ ){
$ Br [] = $ ar [$ I];
}
Return implode (",", $ br );
}
Echo jiequ ($ str, 5th); // 1 and 5 represent the number between the first and.

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.