Code instance sharing of randomly generated names for custom classes in PHP

Source: Internet
Author: User
Tags ming
This article mainly introduces PHP based on the custom class randomly generated names, combined with examples of PHP based on array and string random number operation generated names related to the implementation of the skills, the need for friends can refer to the following

The example in this article describes how PHP generates names randomly based on a custom class. Share to everyone for your reference, as follows:

Custom class rndChinaName.class.php:


<?phpclass rndchinaname{private $arrXing, $numbXing;  Private $arrMing, $numbMing;    function Rndchinaname () {$this->getxinglist ();  $this->getminglist (); }/* Get a list of last names */Private Function getxinglist () {$this->arrxing=array (' Zhao ', ' Qian ', ' sun ', ' Li ', ' Zhou ', ' Wu ', ' Zheng ', ' Wang ', ' Feng ', ' Chen ', ' Chu ') , ' Wei ', ' Jiang ', ' shen ', ' Han ', ' Yang ', ' Zhu ', ' Qin ', ' esp ', ' Xu ', ' ho ', ' lv ', ' shi ', ' Zhang ', ' hole ', ' Cao ', ' Yan ', ' Hua ', ' Jin ', ' Wei ', ' Tao ', ' Ginger ', ' qi ', ' Xie ', ' Zou ', ' Yu ', ' bai ', ' water ', ' Sinus ', ' chapter ', ' Cloud ', ' su ', ' Pan ', ' ge ', ' xi ', ' van ', ' Peng ', ' Lang ', ' Lu ', ' Wei ', ' Chang ', ' ma ', ' Miao ', ' Feng ', ' Hua ', ' Fang ', ' Ren ', ' yuan ', ' Liu ', ' Bao ', ' history ', ' Tang ', ' ' The ', ' Xue ', ' lei ', ' he ' , ' ni ', ' soup ', ' teng ', ' Yin ', ' Luo ', ' bi ', ' Hao ', ' ann ', ' often ', ' Fu ', ' Bian Shenqiu ', ' qi ', ' yuan ', ' gu ', ' Meng ', ' ping ', ' Huang ', ' mu ', ' Shaw ', ' Yin ', ' yao ', ' Shao ', ' Cham ', ' Wang ', ' qi ', ' Mao ', ' di ', ' M ', ' V ', ' Cheng ', ' dai ', ' Talk ', ' song ', ' Mao ', ' Pang ', ' Bear ', ' ji ', ' shu ', ' qu ', ' items ', ' wish ', ' Dong ', ' Liang ', ' du ', ' Ruan ', ' Blue ', ' min ', ' Season ', ' Jia ', ' Lu ', ' Lou ', ' Jiang ', ' Tong ', ' Yan ', ' Guo ' , ' Mei ', ' Sheng ', ' Lin ', ' Bell ', ' Xu ', ' Qiu ', ' Luo ', ' Gao ', ' xia ', ' cai ', ' Tian ', ' fan ', ' Hu ', ' ling ', ' Huo ', ' Yu ', ' Million ', ' branch ', ' ke ', ' tube ', ' Lou ', ' Mo ', ' ke ', ' room ', ' Jo ', ' barthelemy ', ' solution ', ' Should ', ' Zong ', ' ding ', ' Xuan ', ' Deng ', ' single ', ' Hang ', ' hung ', ' package ', ' various ', ' left ', ' stone ', ' cui ', ' ji ', ' gong ', ' Cheng ', ' Kang ', ' Xing ', ' Pei ', ' Lu ', ' Rong ', ' Weng ', ' Xun ', ' in ', ' hui ', ' Zhen ', ' song ', ' Seal ' , ' storage ', ' Zhong ', ' Yi ', ' ning ', ' revenge ', ' gan ', ' wu ', ' symbol ', ' Liu ', ' King ', ' Zhan ', ' Dragon '', ' ye ', ' Fortunately ', ' division ', ' Li ', ' pu ', ' India ', ' bosom ', ' pu ', ' Tai ', ' from ', ' lasso ', ' Lai ', ' Zhuo ', ' slaughter ', ' pool ', ' Joe ', ' Xu ', ' smell ', ' xin ', ' Party ', ' Zhai ', ' tan ', ' gong ', ' Lao ', ' sacrificed ', ' ji ', ' Shen ', ' Help ', ' plugging ', ' ran ', ' slaughter ', ' Yong ', ' sang ', ' Shou ', ' Pass ', ' Yan ', ' pu ', ' Shang ', ' Nong ', ' Wen ', ' Don't ', ' Zhuang ', ' Yan ', ' chai ', ' qu ', ' yen ', ' lian ', ' XI ', ' Rong ', ' to ', ' ancient ', ' easy ', ' Liao ', ' Yu ', ' End ', ' step ', ' all ', ' Geng ', ' full ', ' Hiro ', ' Marina ', ' country ', ' Wen ', ' kou ', ' Guang ', ' lu ', ' que ', ' East ', ' ou ', ' Lee ', ' Division ', ' Gong ', ' nie ', ' Guan ', ' Jing ', ' Sima ', ' Officer ', ' Ouyang ', ' Jaap ', ' ge ', ' Wenren ', ' Orient ', ' Hittite ', ' Huang Fu ', ' shuishe ', ' Ram ', ' Dan Tai ', ' Gong ye ', ' munemasa ', ' Puyang ', ' Chun Yu ', ' Chanyu ', ' Uncle ', ' shentu ', ' Gongsun ', ' Dongsun ', ' shaft ', ' Make fox ', ' Xu ', ' Yu text ', ' grandson ', ' Murong ', '    , ' Sagong '); $this->numbxing = count ($this-arrxing); Total Surname}/* Gets the list of names */Private Function getminglist () {$this->arrming=array (' Wei ', ' just ', ' Yong ', ' Yi ', ' June ', ' Feng ', ' strong ', ' army ', ' flat ', ' Bao ', ' Dong ', ' Wen ', ' hui ', ' Force ', ' Ming ', ' Yong ', ' Jian ', ' world ', ' Guang ', ' zhi ', ' righteousness ', ' xing ', ' good ', ' sea ', ' mountain ', ' benevolence ', ' wave ', ' ning ', ' expensive ', ' blessing ', ' Life ', ' dragon ', ' yuan ', ' full ', ' country ', ' win ', ' Learn ', ' xiang ', ' just ', ' hair ', ' wu ', ' new ', ' Lee ', ' Qing ', ' Fly ', ' bin ', ' rich ', ' shun ', ' faith ', ' son ', ' Jay ', ' Tao ', ' Chang ', ' Cheng ', ' Kang ', ' star ', ' Light ', ' Day ', ' Up ', ' ann ', ' Rock ', ' in ', ' Mao ', ' into ' , ' Forest ', ' have ', ' firm ', ' and ', ' Puma ', ' bo ', ' honesty ', ' first ', ' to ', ' shock ', ' vibration ', ' strong ', ' will ', ' think ', ' group ', ' Hao ', ' heart ', ' state ', ' commitment ', ' music ', ' Shaoxing ', ' work ', ' pine ', ' good ', ' thick ', ' celebrate ', ' lei ', ' People ', ' friends ', ' Yu ', ' River ', ' Zhe ', ' Jiang ', ' super ', ' Hao ', ' bright ', ' politics ', ' humble ', ' Heng ', ' odd', ' solid ', ' it ', ' round ', ' John ', ' Lang ', ' bo ', ' macro ', ' word ', ' if ', ' Ming ', ' friends ', ' bin ', ' Liang ', ' Building ', ' dimension ', ' Kai ', ' g ', ' lun ', ' Xiang ', ' Asahi ', ' Peng ', ' ze ', ' Morning ', ' Chen ', ' Shi ', ' to ', ' Jian ', ' Home ', ' to ', ' tree ', ' inflammation ', ' de ', ' line ', ' when ', ' Ty ', ' sheng ', ' Male ', ' Aachen ', ' June ', ' crown ', ' strategy ', ' teng ', ' nan ', ' Banyan ', ' wind ', ' air ', ' Hiro ', ' show ', ' Juan ', ' Ying ', ' Hua ', ' hui ', ' qiao ', ' Beauty ', ' Na ', ' static ', ' accomplishment ', ' hui ', ' beads ', ' cui ', ' ya ', ' zhi ', ' yu ', ' ping ', ' red ', ' e ', ' ling ', ' Fen ', ' Fang ', ' Yan ', ' cai ', ' Spring ', ' chrysanthemum ', ' orchid ', ' phoenix ', ' Jie ', ' Mei ', ' Lynn ', ' Vegetarian ', ' cloud ', ' lotus ', ' true ' , ' ring ', ' Snow ', ' Glory ', ' love ', ' sister ', ' Chardonnay ', ' incense ', ' month ', ' Ying ', ' yuan ', ' Yan ', ' Rui ', ' where ', ' good ', ' ka ', ' Joan ', ' Qin ', ' Jane ', ' Zhen ', ' Li ', ' GUI ', ' di ', ' ye ', ' Choi ', ' lu ', ' ya ', ' qi ', ' Crystal ', ' shes ', ' alizarin ', ' Autumn ', ' Sam ', ' Lisa ', ' Jin ', ' Dai ', ' green ', ' Qian ', ' ting ', ' jiao ', ' Wan ', ' Jung ', ' Jin ', ' Ying ', ' Lu ', ' Yao ', ' Yi ', ' chan ', ' Goose ', ' Becky ', ' Ceruse ', ' Miriam ', ' Lotus ', ' Dan ', ' Rong ', ' eyebrow ' , ' June ', ' Qin ', ' Rui ', ' Wei ', ' elite ', ' dream ', ' LAN ', ' Yuan ', ' Jay ', ' Xin ', ' na ', ' Yan ', ' Yun ', ' Rong ', ' yuan ', ' Yi ', ' Yong ', ' Qing ', ' Cong ', ' lan ', ' pure ', ' Yu ', ' Yue ', ' Zhao ', ' ice ', ' cool ', ' Wan ', ' Tea ', ' feather ', ' Nozomi ', ' hin ', ' drifting ', ' breeding ', ' Ying ', ' Fu ', ' June ', ' soft ', ' bamboo ', ' Margaret ', ' condensate ', ' Dawn ', ' Huan ', ' xiao ', ' maple ', ' Yun ', ' phenanthrene ', ' cold ', ' Yi ', ' ya ', ' yi ', ' Can ', ' ji ', ' shu ', ' shadow ', ' Lai ' , ' sticks ', ' li ', ' Yang ', ' Nicole ', ' bao ', ' shellfish ', ' early ', ' Cheng ', ' Vatican ', ' gang ', ' Heng ', ' Hung ', ' birch ', ' Hua ', ' sword ', ' jiao ', ' ji ', ' wide ', ' caustic ', ' spirit ', ' ma ', ' Mei ', ' qi ', ' Sunny ', ' Rong ', ' Rui ', ' Shuo ', '    Don ', ' only ', ' Wei ', ' Wei ', ' Wen ', ' Reed ', ' Xuan ', ' read ', ' Yan ', ' Yu ', ' Rain ', ' Ocean ', ' loyalty ', ' Zong ', ' Mann ', ' Purple ', ' Yi ', ' yin ', ' butterfly ', ' Jennifer ', ' green ', ' blue ', ' son ', ' cui ', ' smoke '; $this->numbming = count ($this-arrming);  Total name} private function getxing () {return $this->arrxing [Mt_rand (0, $this->numbxing)];  } Private Function Getming () {return $this->arrming [Mt_rand (0, $this->numbming)];    } Public Function GetName ($type =0) {$name = ';      Switch ($type) {Case 1://2 word $name = $this->getxing (). $this->getming ();      Break      Case 2://Random 2, 3 characters $name = $this->getxing (). $this->getming ();      if (Mt_rand (0,100) >50) $name. = $this->getming ();      Break      Case 3://Take surname $name = $this->getxing ();      Break      Case 4://Name only $name = $this->getming ();      Break    Case 0:default://default 1 Last name + 2 $name = $this->getxing (). $this->getming (). $this->getming ();  } return $name; }}?>

index.php:


<?phprequire ("rndChinaName.class.php"); $name =new rndchinaname (); Echo $name->getname ();//output: Lin Yi Ching?>

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.