Home  >  Article  >  php教程  >  EMS快递单号联想

EMS快递单号联想

WBOY
WBOYOriginal
2016-06-07 11:41:441466browse

给出1张单号,联想出之后的n张单号
PHP版本:<pre class="brush:php;toolbar:false">&lt;?php &lt;br /&gt; &lt;br&gt;     print_r(ems('EK702111856CS',10));&lt;br&gt;     &lt;br&gt;     function ems($code,$num){&lt;br&gt;         if(!preg_match('/[a-z-A-Z]{2}[0-9]{9}[a-z-A-Z]{2}/',$code)) die ('起始值验证失败!不是有效的EMS运单号!');&lt;br&gt;         $start=(float)substr($code,2,8);&lt;br&gt;         for($i=0;$i             $a=(string)($start+$i);&lt;br&gt;             $b=(11-(($a[0]*8+$a[1]*6+$a[2]*4+$a[3]*2+$a[4]*3+$a[5]*5+$a[6]*9+$a[7]*7)%11));&lt;br&gt;             $b=$b             $arr[]=$code[0].$code[1].$a.$b.$code[11].$code[12];&lt;br&gt;         }&lt;br&gt;         return $arr;&lt;br&gt;     }&lt;br&gt; &lt;br&gt; ?&gt;</pre>JavaScript版本:<script><br /> alert(ems(&#039;EK702111856CS&#039;,10));<br /> function ems(code,num){<br /> var a,b,arr=[],start=parseFloat(code.substr(2,8));<br /> for(var i=0;i<num;i++){<br /> a=String(start+i);<br /> b=(11-((a[0]*8+a[1]*6+a[2]*4+a[3]*2+a[4]*3+a[5]*5+a[6]*9+a[7]*7)%11));<br /> b=b<10?b:((b-10)*5);<br /> arr.push(code[0]+code[1]+a+b+code[11]+code[12]);<br /> }<br /> return arr;<br /> }<br /> </script>

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn