Skip to content

Instantly share code, notes, and snippets.

@cloudsben
Created November 7, 2012 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudsben/4029164 to your computer and use it in GitHub Desktop.
Save cloudsben/4029164 to your computer and use it in GitHub Desktop.
截取字符串到指定位置
<?php
for($i=0;$i< 90000; $i++)
{
$a .= ','.rand(10000,99999);
}
// $b = explode(',', $a);
// $c =array_slice($b, 0, 20);
// var_dump($c);
$cc = 0;$pos = 0;
echo $a[0];
for($i=0;$i<500;$i++)
{
//if(substr($a,$i,1)==",")
if($a[$i]==",")
{
$cc++;
}
if($cc==20)
{
$pos = $i;
break;
}
}
$c = substr($a,0,$pos);
echo $c;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment