PHP instance -- generate random strings

Source: Internet
Author: User
/**
+ ----------------------------------------------------------
* Generate a random string, which can be used to automatically generate a password with a default length of 6 characters and a mix of letters and numbers
+ ----------------------------------------------------------
* @ Param string $ LEN Length
* @ Param string $ type string type
* 0, 1, and other digits
* @ Param string $ addchars additional characters
+ ----------------------------------------------------------
* @ Return string
+ ----------------------------------------------------------
*/
FunctionRand_string ($ Len= 6,$ Type= '',$ Addchars= ''){
$ Str= '';
Switch($ Type){
Case0:
$ Chars= 'Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy '.$ Addchars;
Break;
Case1:
$ Chars=Str_repeat('123', 3 );
Break;
Case2:
$ Chars= 'Abcdefghijklmnopqrstuvwxy '.$ Addchars;
Break;
Case3:
$ Chars= 'Abcdefghijklmnopqrstuvwxy '.$ Addchars;
Break;
Case4:
$ Chars = "When I come to him, I want to work in China. First, I want to work in order to become a people who can be outputted. When there is no such person, I will come to the secondary school. I use my peers to say that I have lived a great deal of life, and after many sub-accounts, I am working on social networks and small hosts, and I am working on the power line. This is a large amount of electricity. before the three-year war and ten-year war, the road map of anti-body and fighting will begin to discuss the new things from when two or more tianzi event teams approve and emphasize their thinking and in-room promotion phase by the pressure officer gas industry on behalf of the whole group number fruit phase guide each base or month Mao ran as if the shape of the mind-like do all to change the Customs question than show it most out-of-the-box did not see governance raise five the solution Forest's rice clusters mean only four horses recognize the article but the article is more grams and the Public hole leads into the seat transport and fly the crude oil to set up the question Quality refers to the establishment of a district to test the crowd therefore, Chang shiqiang is already rooted in a total of direct mission-style conversion and cut-9 You take the west holding total materials re-election Zhi Guan tune seven What mountain Cheng baibao more see must be really holding hot Commission hand change the management department has fixed the awareness of the disease as several first, the old light species, the sixth type with the instructions of the Fu 'an belt, each East, then the wind back to the south wide labor wheel north to build a car to the festival to do the work is the whole link class set number column temperature installation is no know Axis research solid color fast anti-shi Lashi set dalon weaving calendar flowers by seeking to pass the mouth broken condition mining fine gold industry product determination parameter layer end side clear to ten indeed research books the surgical factory must be away from the eyes of the sea, and the children's qingcai certificate is low, the eight trial rules are near the injection of the bumen iron should go to the county, the soldiers fixed in addition to the teeth like a thousand wins fine shadows ji bai ge effect set push blank configuration knife leaf rate description today selected yangde phone query difference half enemy starting film Shi Xiang Hua Jue slave name red continuous average drug mark difficult to store tester body tight liquid send quasi Jin Jiao Dimensionality Reduction ban Xu broke the technology to eliminate the bottom of the bed field trend sense to Shen benhe village structure photo volume not engaged in sub-grinding family fire section calculation according to the value of the United States Huang Yi Biao service early shift Mai cutting mail as the audience said, the attacker Zhang miwei, Hou Cao, He shufa, followed by the city's strict-diameter screw inspection on the Left page, anti-suxian, bitter English, fast-known as bad migration, and the province of BA Pai, He Weihe only needle how to plant Jing Zhu shengwang eye she grasp containing seedlings sub-Miscellaneous talk about food shot source examples caused by acid old but adequate short drag agent Xuan Ring falls first ruler wave Bearing Powder Jian Fu fish with the test engraved rely on enough full husband loss to wrap up promote branch bacteria rod weekly Yan teacher pick Qu chunyuan ultra negative sand seal for too much poor reduction Yang Jiang Mu Yan ball Chao Medical School ancient? circle Wei Season Training Control exciting look called cloud mutual split grain mother trainer plug steel top policy double stay mistaken Foundation suck blocking so inch shield late silk female powder Welding Power Plants Cold Spring false scattered commodity video art destroy version strong zero room light blood times lack of PCT pump check absolutely rich City Chong spray soil simple no column Li wangpan magnetic Xiong seems sleepy Yi Zhou off cast to slave side Run cover swing from trigger xingsong to get xingdu official mixed Ji according to not burst frame Wide winter seal wet partial grain eat executive valve mine village responsibility cooked stable hard price nugo Qijia pre-job evaluation read back Association loss of cotton invasion of gray although the spear thick Luo mud open the egg box ops oxygen love stopped once dissolved camp final gang Meng Qian to do Russia to shrink sand back Chen Fen machinery carrying young which stripping force spin collection slot inverted hold is still ah fresh it card rough drill by weak feet afraid of salt at the end of Yin Feng fog C Street laibei spoke sausage Fu Ji Xi Rui stunned squeeze seconds suspension M rotten sen sugar Sheng concave pottery word late silkworm Yi moment Kang zumu by the frame garden cavity set xiangmeat younger brother house min Hui forgot to edit printing bee rush take expansion injury flying dew nuclear edge game vibration operation Central Wu domain very Xunhui different sequence free paper night township JIU licylinder folder Nian LAN Ying Gou Yi Ru kill steam phosphorus Jing plug Yi huan iron fill yi ya Wing Wa tilting Array Carbon play Wei Fu ya Yong tile oblique irrigation ou Xian shun pig foreign rot please pass the division of dangerous pulse should laugh if the tail bunch of strong and violent enterprises food Sui Chu Han more green drag ox copy dyeing autumn round forging Yu Xia treatment tip colony jing Fei Zhou visits blowing Rong copper along the rolling passenger call drought Wu Zhi nancu Piao Tibet dare to make Gap shell sulfur coal yingzhu stick probe thin late shanfu longitudinal selection ceremony may Fu residual mine yan sentence pure gradual cultivation run ze slow planting Lu chifan environment tide off cone Xi Chi defeat ship false Bright said to the gang Zhe Huai cut the tribute was strong financial instrument sinning Ma sin zuxi car wear goods sales Qi rat pumping painting feeding longku shouzhu house Song Han Xi brother wash eclipse waste na belly almost recording mirror women evil fat village wipe risk likes Bell shake the handle debate zhugu sell chaos virtual bridge Obo catch the way of the amount of the wall network cut wild left quiet seek to get the hanging class town arrogant Sheng aid Zha worry key Fu Qing together around the moo Busy dance met suo Gu Jiao yanghu dingtalk renyin trace broken stretch lamp to avoid Pan death answer Yong frequency Huang Liu ha uncover ganuo summary Xian concentrated island attack who Hong Xie gun pouring spot news understand spirit egg closed children release milk giant private yin Yi Jing tan tired Yun Mo dulle Bending Performance recruit Shao Hu call pain peak 0 Chai spring Wu jump Ju Shang Ding Qin slightly chasing Liang discount alkali shugang dig blade drama hehe chest heng Qin film published in the case of slow and convex active cut Sichuan snow chain Yu la face households Luo shu Bo Meng buy Yang zongjiao saqi filter silicon carbon shares sitting Steam Condensate actually trapped gun Li rescue hidden Holes criminal tube you song arc burst paradox tu flavor Jin arm barrier brown Lu Jian Zun bean pull Mo against Sanpo sewing police pick dirty ice Cambodia mouth what rice plastic sent Zhao shout mat Dan du ear planing Tiger pen thin Kun langsa tea drops showner points covered by LUN Niang tons of Tea dipped sleeve beads female Mazi opera tower hammer Zhen-old appearance Jie Section Prison suspect PA flash Po fierce v brush malicious disaster recovery noisy Joe Tang leak smell Shen melting chlorine waste stem man who snatched like pulp beside Bo also loyal to sing mengyu to catch the lock especially by Wuzhi light allow rebellion animal capture rust sweep bibao Core ye Jian Mi Jing Jiang calcium shoulder Teng dry throwing track Hall mix dad follow the temptation Zhu liken wine rope poor pond dry Bubble bag Lang feed aluminum soft canal used trade dung integrated wall trend his session mo wanqi reverse unloading clothing Sun Lingling cheat Hugh borrow ".$ Addchars ;
Break;
Default:
//Ooll and number 01 are removed by default. To add them, use the addchars parameter.
$ Chars= 'Abcdefghijkmnpqrstuvwxyzabcdefghijkmnpqrstuvwxyz23456789 '.$ Addchars;
Break;
}
If($ Len> 10 ){//The number of digits is too long to repeat the string for a certain number of times.
$ Chars=$ Type= 1?Str_repeat($ Chars,$ Len):Str_repeat($ Chars, 5 );
}
If($ Type! = 4 ){
$ Chars=Str_shuffle($ Chars);
$ Str=Substr($ Chars, 0,$ Len);
}Else{
//Chinese random words
For($ I= 0;$ I<$ Len;$ I++ ){
$ Str. = Msubstr ($ Chars,Floor(Mt_rand(0, mb_strlen ($ Chars, 'Utf-8')-1), 1 );
}
}
Return $ Str;
}

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.