HumHub Documentation (unofficial)

Text extends Text
in package

Table of Contents

Properties

$baseText  : string
License: Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
$consecutiveWords  : mixed
$explodedText  : mixed
$generator  : Generator
$separator  : mixed
$separatorLen  : mixed
$textStartsWithUppercase  : mixed
$unique  : UniqueGenerator

Methods

__construct()  : mixed
asciify()  : string
Replaces * signs with random numbers and letters and special characters
bothify()  : string
Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter
lexify()  : string
Replaces all question mark ('?') occurrences with a random letter
numberBetween()  : int
Returns a random number between $int1 and $int2 (any order)
numerify()  : string
Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number
optional()  : mixed|null
Chainable method for making any formatter optional.
passthrough()  : mixed
Returns the passed value
randomAscii()  : string
Returns a random ASCII character (excluding accents and special chars)
randomDigit()  : int
Returns a random number between 0 and 9
randomDigitNot()  : int
Generates a random digit, which cannot be $except
randomDigitNotNull()  : int
Returns a random number between 1 and 9
randomElement()  : mixed
Returns a random element from a passed array
randomElements()  : array<string|int, mixed>
Returns randomly ordered subsequence of $count elements from a provided array
randomFloat()  : float
Return a random float number
randomKey()  : int|string|null
Returns a random key from a passed associative array
randomLetter()  : string
Returns a random letter from a to z
randomNumber()  : int
Returns a random integer with 0 to $nbDigits digits.
realText()  : string
Generate a text string by the Markov chain algorithm.
realTextBetween()  : string
Generate a text string by the Markov chain algorithm.
regexify()  : string
Transforms a basic regular expression into a random string satisfying the expression.
shuffle()  : array<string|int, mixed>|string
Returns a shuffled version of the argument.
shuffleArray()  : array<string|int, mixed>
Returns a shuffled version of the array.
shuffleString()  : string
Returns a shuffled version of the string.
toLower()  : string
Converts string to lowercase.
toUpper()  : string
Converts string to uppercase.
unique()  : UniqueGenerator
Chainable method for making any formatter unique.
valid()  : ValidGenerator
Chainable method for forcing any formatter to return only valid values.
appendEnd()  : mixed
explode()  : mixed
generateText()  : string
getConsecutiveWords()  : mixed
getExplodedText()  : mixed
implode()  : mixed
strlen()  : mixed
validStart()  : mixed
replaceWildcard()  : mixed

Properties

$baseText

License: Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

protected static string $baseText = <<<'EOT' ففي الليلة الأولى قالت: بلغني أيها الملك السعيد أنه كان تاجر من التجار كثير المال والمعاملات في البلاد قد ركب يومًا وخرج يطالب في بعض البلاد فاشتد عليه الحر فجلس تحت شجرة وحط يده في خرجه وأكل كسرة كانت معه وتمرة فلما فرغ من أكل التمرة رمى النواة وإذا هو بعفريت طويل القامة وبيده سيف فدنا من ذلك التاجر وقال له: قم حتى أقتلك مثل ما قتلت ولدي فقال له التاجر: كيف قتلت ولدك قال له: لما أكلت التمرة ورميت نواتها جاءت النواة في صدر ولدي فقضي عليه ومات من ساعته فقال التاجر للعفريت: أعلم أيها العفريت أني على دين ولي مال كثير وأولاد وزوجة وعندي رهون فدعني أذهب إلى بيتي وأعطي كل ذي حق حقه ثم أعود إليك ولك علي عهد وميثاق أني أعود إليك فتفعل بي ما تريد والله على ما أقول وكيل. فاستوثق منه الجني وأطلقه فرجع إلى بلده وقضى جميع تعلقاته وأوصل الحقوق إلى أهلها وأعلم زوجته وأولاده بما جرى له فبكوا وكذلك جميع أهله ونساءه وأولاده وأوصى وقعد عندهم إلى تمام السنة ثم توجه وأخذ كفنه تحت إبطه وودع أهله وجيرانه وجميع أهله وخرج رغمًا عن أنفه وأقيم عليه العياط والصراخ فمشى إلى أن وصل إلى ذلك البستان وكان ذلك اليوم أول السنة الجديدة فبينما هو جالس يبكي على ما يحصل له وإذا بشيخ كبير قد أقبل عليه ومعه غزالة مسلسلة فسلم على هذا التاجر وحياه وقال له: ما سبب جلوسك في هذا المكان وأنت منفرد وهو مأوى الجن فأخبره التاجر بما جرى له مع ذلك العفريت وبسبب قعوده في هذا منهم الشيخ الأول وهو صاحب الغزالة وقبل يد ذلك العفريت وقال له: يا أيها الجني وتاج ملوك الجن إذا حكيت لك حكايتي مع هذه الغزالة ورأيتها عجيبة أتهب لي ثلث دم هذا التاجر قال: نعم. يا أيها الشيخ إذا أنت حكيت لي الحكاية ورأيتها عجيبة وهبت لك ثلث دمه فقال ذلك الشيخ الأول: اتعلم يا أيها العفريت أن هذه الغزالة هي بنت عمي ومن لحمي ودمي وكنت تزوجت بها وهي صغيرة السن وأقمت معها نحو ثلاثين سنة فلم أرزق منها بولد فأخذت لي سرية فرزقت منها بولد ذكر كأنه البدر إذا بدا بعينين مليحتين وحاجبين مزججين وأعضاء كاملة فكبر شيئًا فشيئًا إلى أن صار ابن خمس عشرة سنة فطرأت لي سفرة إلى بعض المدن فسافرت بمتجر عظيم وكانت بنت عمي هذه الغزالة تعلمت السحر والكهانة من صغرها فسحرت ذلك الولد عجلًا وسحرت الجارية أمه بقرة وسلمتها إلى الراعي ثم جئت أنا بعد مدة طويلة من السفر فسألت عن ولدي وعن أمه فقالت لي جاريتك ماتت وابنك هرب ولم أعلم أين راح فجلست مدة سنة وأنا حزين القلب باكي العين إلى أن جاء عيد الضحية فأرسلت إلى الراعي أن يخصني ببقرة سمينة وهي سريتي التي سحرتها تلك الغزالة فشمرت ثيابي وأخذت السكين بيدي وتهيأت لذبحها فصاحت وبكت بكاء شديدًا فقمت عنها وأمرت ذلك الراعي بذبحها وسلخها فلم يجد فيها شحمًا ولا لحمًا غير جلد وعظم فندمت على ذبحها حيث لا ينفعني الندم وأعطيتها للراعي وقلت له: ائتني بعجل سمين فأتاني بولدي المسحور عجلًا فلما رآني ذلك العجل قطع حبله وجاءني وتمرغ علي وولول وبكى فأخذتني الرأفة عليه وقلت للراعي ائتني ببقرة ودع هذا. وأدرك شهرزاد الصباح فسكتت عن الكلام المباح. فقالت لها أختها: ما أطيب حديثك وألطفه وألذه وأعذبه فقالت: وأين هذا مما أحدثكم به الليلة القابلة إن عشت وأبقاني الملك فقال الملك في نفسه: والله ما أقتلها حتى أسمع بقية حديثها ثم أنهم باتوا تلك الليلة إلى الصباح متعانقين فخرج الملك إلى محل حكمه وطلع الوزير بالكفن تحت إبطه ثم حكم الملك وولي وعزل إلى آخر النهار ولم يخبر الوزير بشيء من ذلك فتعجب الوزير غاية العجب ثم انفض الديوان ودخل الملك شهريار قصره. و في الليلة الثانية قالت دنيازاد لأختها شهرزاد: يا أختي أتممي لنا حديثك الذي هو حديث التاجر والجني. قالت حبًا وكرامة إن أذن لي الملك في ذلك فقال لها الملك: احكي فقالت: بلغني أيها الملك السعيد ذو الرأي الرشيد أنه لما رأى بكاء العجل حن قلبه إليه وقال للراعي: ابق هذا العجل بين البهائم. كل ذلك والجني يتعجب من حكاية ذلك الكلام العجيب ثم قال صاحب الغزالة: يا سيد ملوك الجان كل ذلك جرى وابنة عمي هذه الغزالة تنظر وترى وتقول اذبح هذا العجل فإنه سمين فلم يهن علي أن أذبحه وأمرت الراعي أن يأخذه وتوجه به ففي ثاني يوم وأنا جالس وإذا بالراعي أقبل علي وقال: يا سيدي إني أقول شيئًا تسر به ولي البشارة. فقلت: نعم فقال: أيها التاجر إن لي بنتًا كانت تعلمت السحر في صغرها من امرأة عجوز كانت عندنا فلما كنا بالأمس وأعطيتني العجل دخلت به عليها فنظرت إليه ابنتي وغطت وجهها وبكت ثم إنها ضحكت وقالت: يا أبي قد خس قدري عندك حتى تدخل علي الرجال الأجانب. فقلت لها: وأين الرجال الأجانب ولماذا بكيت وضحكت فقالت لي أن هذا العجل الذي معك ابن سيدي التاجر ولكنه مسحور وسحرته زوجة أبيه هو وأمه فهذا سبب ضحكي وأما سبب بكائي فمن أجل أمه حيث ذبحها أبوه فتعجبت من ذلك غاية العجب وما صدقت بطلوع الصباح حتى جئت إليك لأعلمك فلما سمعت أيها الجني كلام هذا الراعي خرجت معه وأنا سكران من غير مدام من كثرة الفرح والسرور والذي حصل لي إلى أن أتيت إلى داره فرحبت بي ابنة الراعي وقبلت يدي ثم إن العجل جاء إلي وتمرغ علي فقلت لابنة الراعي: أحق ما تقولينه عن ذلك العجل فقالت: نعم يا سيدي إيه ابنك وحشاشة كبدك فقلت لها: أيها الصبية إن أنت خلصتيه فلك عندي ما تحت يد أبيك من المواشي والأموال فتبسمت وقالت: يا سيدي ليس لي رغبة في المال إلا بشرطين: الأول: أن تزوجني به والثاني: أن أسر من سحرته وأحبسها وإلا فلست آمن مكرها فلما سمعت أيها الجني كلام بنت الراعي قلت : ولك فوق جميع ما تحت يد أبيك من الأموال زيادة وأما بنت عمي فدمها لك مباح. فلما سمعت كلامي أخذت طاسة وملأتها ماء ثم أنها عزمت عليها ورشت بها العجل وقالت: إن كان الله خلقك عجلًا فدم على هذه الصفة ولا تتغير وإن كنت مسحورًا فعد إلى خلقتك الأولى بإذن الله تعالى وإذا به انتفض ثم صار إنسانًا فوقعت عليه وقلت له: بالله عليك احك لي جميع ما صنعت بك وبأمك بنت عمي فحكى لي جميع ما جرى لهما فقلت: يا ولدي قد قيض الله لك من خلصك وخلص حقك ثم إني أيها الجني زوجته ابنة الراعي ثم أنها سحرت ابنة عمي هذه الغزالة وجئت إلى هنا فرأيت هؤلاء الجماعة فسألتهم عن حالهم فأخبروني بما جرى لهذا التاجر فجلست لأنظر ما يكون وهذا حديثي فقال الجني: هذا حديث عجيب وقد وهبت لك ثلث دمه فعند ذلك تقدم الشيخ صاحب الكلبتين السلاقيتين وقال له: اعلم يا سيد ملوك الجان أن هاتين الكلبتين أخوتي وأنا ثالثهم ومات والدي وخلف لنا ثلاثة آلاف دينار ففتحت دكانًا أبيع فيه وأشتري وسافر أخي بتجارته وغاب عنا مدة سنة مع القوافل ثم أتى وما معه شيء فقلت له: يا أخي أما أشرت عليك بعدم السفر فبكى وقال: يا أخي قدر الله عز وجل علي بهذا ولم يبق لهذا الكلام فائدة ولست أملك شيئًا فأخذته وطلعت به إلى الدكان ثم ذهبت به إلى الحمام وألبسته حلة من الملابس الفاخرة وأكلت أنا وإياه وقلت له: يا أخي إني أحسب ربح دكاني من السنة إلى السنة ثم أقسمه دون رأس المال بيني وبينك ثم إني عملت حساب الدكان من بربح مالي فوجدته ألفي دينار فحمدت الله عز وجل وفرحت غاية الفرح وقسمت الربح بيني وبينه شطرين وأقمنا مع بعضنا أيامًا ثم إن أخوتي طلبوا السفر أيضًا وأرادوا أن أسافر معهم فلم أرض وقلت لهم: أي شيء كسبتم من سفركم حتى أكسب أنا فألحوا علي ولم أطعهم بل أقمنا في دكاكيننا نبيع ونشتري سنة كاملة وهم يعرضون علي السفر وأنا لم أرض حتى مضت ست سنوات كوامل. ثم وافقتهم على السفر وقلت لهم: يا أخوتي إننا نحسب ما عندنا من المال فحسبناه فإذا هو ستة آلاف دينار فقلت: ندفن نصفها تحت الأرض لينفعا إذا أصابنا أمر ويأخذ كل واحد منا ألف دينار ونتسبب فيها قالوا: نعم الرأي فأخذت المال وقسمته نصفين ودفنت ثلاثة آلاف دينار. وأما الثلاثة آلاف الأخرى فأعطيت كل واحد منهم ألف دينار وجهزنا بضائع واكترينا مركبًا ونقلنا فيها حوائجنا وسافرنا مدة شهر كامل إلى أن دخلنا مدينة وبعنا بضائعنا فربحنا في الدينار عشرة دنانير ثم أردنا السفر فوجدنا على شاطئ البحر جارية عليها خلق مقطع فقبلت يدي وقالت: يا سيدي هل عندك إحسان ومعروف أجازيك عليهما قلت: نعم إن عندي الإحسان والمعروف ولو لم تجازيني فقالت: يا سيدي تزوجني وخذني إلى بلادك فإني قد وهبتك نفسي فافعل معي معروفًا لأني ممن يصنع معه المعروف والإحسان ويجازي عليهما ولا يغرنك حالي. فلما سمعت كلامها حن قلبي إليها لأمر يريده الله عز وجل فأخذتها وكسوتها وفرشت لها في المركب فرشًا حسنًا وأقبلت عليها وأكرمتها ثم سافرنا وقد أحبها قلبي محبة عظيمة وصرت لا أفارقها ليلًا ولا نهارًا أو اشتغلت بها عن إخوتي فغاروا مني وحسدوني على مالي وكثرت بضاعتي وطمحت عيونهم في المال جميعه وتحدثوا بقتلي وأخذ مالي وقالوا: نقتل أخانا ويصير المال جميعه لنا وزين لهم الشيطان أعمالهم فجاؤوني وأنا نائم بجانب زوجتي ورموني في البحر فلما استيقظت زوجتي انتفضت فصارت عفريتة وحملتني وأطلعتني على جزيرة وغابت عني قليلًا وعادت إلي عند الصباح وقالت لي: أنا زوجتك التي حملتك ونجيتك من القتل بإذن الله تعالى واعلم أني جنية رأيتك فحبك قلبي وأنا مؤمنة بالله ورسوله فجئتك بالحال الذي رأيتني فيه فتزوجت بي وها أنا قد نجيتك من الغرق وقد غضبت على إخوتك ولا بد أن أقتلهم. فلما سمعت حكايتها تعجبت وشكرتها على فعلها وقلت لها أما هلاك إخوتي فلا ينبغي ثم حكيت لها ما جرى لي معهم من أول الزمان إلى آخره. فلما سمعت كلامي قالت: أنا في هذه الليلة أطير إليهم وأغرق مراكبهم وأهلكهم فقلت لها: بالله لا تفعلي فإن صاحب المثل يقول: يا محسنًا لمن أساء كفي المسيء فعله وهم إخوتي على كل حال قالت لا بد من قتلهم فاستعطفتها ثم أنها حملتني وطارت فوضعتني على سطح داري ففتحت الأبواب وأخرجت الذي خبأته تحت الأرض وفتحت دكاني بعد ما سلمت على الناس واشتريت بضائع فلما كان الليل دخلت داري فوجدت هاتين الكلبتين مربوطتين فيها فلما رأياني قاما إلي وبكيا وتعلقا بي فلم أشعر إلا وزوجتي قالت هؤلاء إخوتك فقلت من فعل بهم هذا الفعل قالت أنا أرسلت إلى أختي ففعلت بهم ذلك وما يتخلصون إلا بعد عشر سنوات فجئت وأنا سائر إليها تخلصهم بعد إقامتهم عشر سنوات في هذا الحال فرأيت هذا الفتى قال الجني: إنها حكاية عجيبة وقد وهبت لك ثلث دمه في جنايته فعند ذلك تقدم الشيخ الثالث صاحب البغلة وقال للجني أنا أحكي لك حكاية أعجب من حكاية الاثنين وتهب لي باقي دمه وجنايته فقال الجني نعم فقال الشيخ أيها السلطان ورئيس الجان إن هذه البغلة كانت زوجتي سافرت وغبت عنها سنة كاملة ثم قضيت سفري وجئت إليها في الليل فرأيت عبد أسود راقد معها في الفراش وهما في كلام وغنج وضحك وتقبيل وهراش فلما رأتني عجلت وقامت إلي بكوز فيه ماء فتكلمت عليه ورشتني وقالت اخرج من هذه الصورة إلى صورة كلب فصرت في الحال كلبًا فطردتني من البيت فخرجت من الباب ولم أزل سائرًا حتى وصلت دكان جزار فتقدمت وصرت آكل من العظام. فلما رآني صاحب الدكان أخذني ودخل بي بيته فلما رأتني بنت الجزار غطت وجهها مني فقالت أتجيء لنا برجل وتدخل علينا به فقال أبوها أين الرجل قالت إن هذا الكلب سحرته امرأة وأنا أقدر على تخليصه فلما سمع أبوها كلامها قال: بالله عليك يا بنتي خلصيه فأخذت كوزًا فيه ماء وتكلمت عليه ورشت علي منه قليلًا وقالت: اخرج من هذه الصورة إلى صورتك الأولى فصرت إلى صورتي الأولى فقبلت يدها وقلت لها: أريد أن تسحري زوجتي كما سحرتني فأعطتني قليلًا من الماء وقالت إذا رأيتها نائمة فرش هذا الماء عليها فإنها تصير كما أنت طالب فوجدتها نائمة فرششت عليها الماء وقلت اخرجي من هذه الصورة إلى صورة بغلة فصارت في الحال بغلة وهي هذه التي تنظرها بعينك أيها السلطان ورئيس ملوك الجان ثم التفت إليها وقال: أصحيح هذا فهزت رأسها وقالت بالإشارة نعم هذا صحيح فلما فرغ من حديثه اهتز الجني من الطرب ووهب له باقي دمه وأدرك شهرزاد الصباح فسكتت عن الكلام المباح. فقالت لها أختها: يا أختي ما أحلى حديثك وأطيبه وألذه وأعذبه فقالت: أين هذا مما أحدثكم به الليلة القابلة إن عشت وأبقاني الملك فقال الملك: والله لا أقتلها حتى أسمع بقية حديثها لأنه عجيب ثم باتوا تلك الليلة متعانقين إلى الصباح فخرج الملك إلى محل حكمه ودخل عليه الوزير والعسكر واحتبك الديوان فحكم الملك وولى وعزل ونهى وأمر إلى آخر النهار ثم انفض الديوان ودخل الملك شهريار إلى قصره. وفي الليلة الثالثة قالت لها أختها دنيا زاد : يا أختي أتمي لنا حديثك فقالت حبًا وكرامة بلغني أيها الملك السعيد أن التاجر أقبل على الشيوخ وشكرهم هنوه بالسلامة ورجع كل واحد إلى بلده وما هذه بأعجب من حكاية الصياد فقال لها الملك: وما حكاية الصياد؟يا ناس اقرأو الكتب فالكتب مشوقة و اتمنى ان تقرأوا القصة التالية لانها مشوقة . EOT

Title: ألف ليلة وليلة Language: Arabic

Tags
see
https://ar.wikisource.org/wiki/%D8%A3%D9%84%D9%81_%D9%84%D9%8A%D9%84%D8%A9_%D9%88%D9%84%D9%8A%D9%84%D8%A9/%D8%A7%D9%84%D8%AC%D8%B2%D8%A1_%D8%A7%D9%84%D8%A3%D9%88%D9%84

$consecutiveWords

protected mixed $consecutiveWords = []

$explodedText

protected mixed $explodedText

$separator

protected static mixed $separator = ' '

$separatorLen

protected static mixed $separatorLen = 1

$textStartsWithUppercase

protected static mixed $textStartsWithUppercase = true

Methods

asciify()

Replaces * signs with random numbers and letters and special characters

public static asciify([string $string = '****' ]) : string
Parameters
$string : string = '****'

String that needs to bet parsed

Tags
example

$faker->asciify(''********'); // "s5'G!uC3"

Return values
string

bothify()

Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter

public static bothify([string $string = '## ??' ]) : string
Parameters
$string : string = '## ??'

String that needs to be parsed

Return values
string

lexify()

Replaces all question mark ('?') occurrences with a random letter

public static lexify([string $string = '????' ]) : string
Parameters
$string : string = '????'

String that needs to bet parsed

Return values
string

numberBetween()

Returns a random number between $int1 and $int2 (any order)

public static numberBetween([int $int1 = 0 ][, int $int2 = 2147483647 ]) : int
Parameters
$int1 : int = 0

default to 0

$int2 : int = 2147483647

defaults to 32 bit max integer, ie 2147483647

Tags
example

79907610

Return values
int

numerify()

Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number

public static numerify([string $string = '###' ]) : string
Parameters
$string : string = '###'

String that needs to bet parsed

Return values
string

optional()

Chainable method for making any formatter optional.

public optional([float|int $weight = 0.5 ][, mixed $default = null ]) : mixed|null
Parameters
$weight : float|int = 0.5

Set the probability of receiving a null value. "0" will always return null, "1" will always return the generator. If $weight is an integer value, then the same system works between 0 (always get false) and 100 (always get true).

$default : mixed = null
Return values
mixed|null

passthrough()

Returns the passed value

public static passthrough(mixed $value) : mixed
Parameters
$value : mixed

randomAscii()

Returns a random ASCII character (excluding accents and special chars)

public static randomAscii() : string
Return values
string

randomDigit()

Returns a random number between 0 and 9

public static randomDigit() : int
Return values
int

randomDigitNot()

Generates a random digit, which cannot be $except

public static randomDigitNot(int $except) : int
Parameters
$except : int
Return values
int

randomDigitNotNull()

Returns a random number between 1 and 9

public static randomDigitNotNull() : int
Return values
int

randomElement()

Returns a random element from a passed array

public static randomElement([array<string|int, mixed>|class-string|Traversable $array = ['a', 'b', 'c'] ]) : mixed
Parameters
$array : array<string|int, mixed>|class-string|Traversable = ['a', 'b', 'c']
Tags
throws
InvalidArgumentException

randomElements()

Returns randomly ordered subsequence of $count elements from a provided array

public static randomElements([array<string|int, mixed>|class-string|Traversable $array = ['a', 'b', 'c'] ][, int|null $count = 1 ][, bool $allowDuplicates = false ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>|class-string|Traversable = ['a', 'b', 'c']

Array to take elements from. Defaults to a-c

$count : int|null = 1

Number of elements to take. If null then returns random number of elements

$allowDuplicates : bool = false

Allow elements to be picked several times. Defaults to false

Tags
todo

update default $count to null (BC) for next major version

throws
InvalidArgumentException
throws
LengthException

When requesting more elements than provided

Return values
array<string|int, mixed>

New array with $count elements from $array

randomFloat()

Return a random float number

public static randomFloat([int $nbMaxDecimals = null ][, float|int $min = 0 ][, float|int $max = null ]) : float
Parameters
$nbMaxDecimals : int = null
$min : float|int = 0
$max : float|int = null
Tags
example

48.8932

Return values
float

randomKey()

Returns a random key from a passed associative array

public static randomKey([array<string|int, mixed> $array = [] ]) : int|string|null
Parameters
$array : array<string|int, mixed> = []
Return values
int|string|null

randomLetter()

Returns a random letter from a to z

public static randomLetter() : string
Return values
string

randomNumber()

Returns a random integer with 0 to $nbDigits digits.

public static randomNumber([int $nbDigits = null ][, bool $strict = false ]) : int

The maximum value returned is mt_getrandmax()

Parameters
$nbDigits : int = null

Defaults to a random number between 1 and 9

$strict : bool = false

Whether the returned number should have exactly $nbDigits

Tags
example

79907610

Return values
int

realText()

Generate a text string by the Markov chain algorithm.

public realText([int $maxNbChars = 200 ][, int $indexSize = 2 ]) : string

Depending on the $maxNbChars, returns a random valid looking text. The algorithm generates a weighted table with the specified number of words as the index and the possible following words as the value.

Parameters
$maxNbChars : int = 200

Maximum number of characters the text should contain (minimum: 10)

$indexSize : int = 2

Determines how many words are considered for the generation of the next word. The minimum is 1, and it produces a higher level of randomness, although the generated text usually doesn't make sense. Higher index sizes (up to 5) produce more correct text, at the price of less randomness.

Tags
example

'Alice, swallowing down her flamingo, and began by taking the little golden key'

Return values
string

realTextBetween()

Generate a text string by the Markov chain algorithm.

public realTextBetween([int $minNbChars = 160 ][, int $maxNbChars = 200 ][, int $indexSize = 2 ]) : string

Depending on the $maxNbChars, returns a random valid looking text. The algorithm generates a weighted table with the specified number of words as the index and the possible following words as the value.

Parameters
$minNbChars : int = 160

Minimum number of characters the text should contain (maximum: 8)

$maxNbChars : int = 200

Maximum number of characters the text should contain (minimum: 10)

$indexSize : int = 2

Determines how many words are considered for the generation of the next word. The minimum is 1, and it produces a higher level of randomness, although the generated text usually doesn't make sense. Higher index sizes (up to 5) produce more correct text, at the price of less randomness.

Tags
example

'Alice, swallowing down her flamingo, and began by taking the little golden key'

Return values
string

regexify()

Transforms a basic regular expression into a random string satisfying the expression.

public static regexify([string $regex = '' ]) : string
Parameters
$regex : string = ''

A regular expression (delimiters are optional)

Tags
example

$faker->regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}'); // sm0@y8k96a.ej

Regex delimiters '/.../' and begin/end markers '^...$' are ignored.

Only supports a small subset of the regex syntax. For instance, unicode, negated classes, unbounded ranges, subpatterns, back references, assertions, recursive patterns, and comments are not supported. Escaping support is extremely fragile.

This method is also VERY slow. Use it only when no other formatter can generate the fake data you want. For instance, prefer calling $faker->email rather than regexify with the previous regular expression.

Also note than bothify can probably do most of what this method does, but much faster. For instance, for a dummy email generation, try $faker->bothify('?????????@???.???').

see
https://github.com/icomefromthenet/ReverseRegex

for a more robust implementation

Return values
string

shuffle()

Returns a shuffled version of the argument.

public static shuffle([array<string|int, mixed>|string $arg = '' ]) : array<string|int, mixed>|string

This function accepts either an array, or a string.

Parameters
$arg : array<string|int, mixed>|string = ''

The set to shuffle

Tags
example

$faker->shuffle([1, 2, 3]); // [2, 1, 3]

example

$faker->shuffle('hello, world'); // 'rlo,h eold!lw'

see
shuffleArray()
see
shuffleString()
Return values
array<string|int, mixed>|string

The shuffled set

shuffleArray()

Returns a shuffled version of the array.

public static shuffleArray([array<string|int, mixed> $array = [] ]) : array<string|int, mixed>

This function does not mutate the original array. It uses the Fisher–Yates algorithm, which is unbiased, together with a Mersenne twister random generator. This function is therefore more random than PHP's shuffle() function, and it is seedable.

Parameters
$array : array<string|int, mixed> = []

The set to shuffle

Tags
see
http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
example

$faker->shuffleArray([1, 2, 3]); // [2, 1, 3]

Return values
array<string|int, mixed>

The shuffled set

shuffleString()

Returns a shuffled version of the string.

public static shuffleString([string $string = '' ][, string $encoding = 'UTF-8' ]) : string

This function does not mutate the original string. It uses the Fisher–Yates algorithm, which is unbiased, together with a Mersenne twister random generator. This function is therefore more random than PHP's shuffle() function, and it is seedable. Additionally, it is UTF8 safe if the mb extension is available.

Parameters
$string : string = ''

The set to shuffle

$encoding : string = 'UTF-8'

The string encoding (defaults to UTF-8)

Tags
see
http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
example

$faker->shuffleString('hello, world'); // 'rlo,h eold!lw'

Return values
string

The shuffled set

toLower()

Converts string to lowercase.

public static toLower([string $string = '' ]) : string

Uses mb_string extension if available.

Parameters
$string : string = ''

String that should be converted to lowercase

Return values
string

toUpper()

Converts string to uppercase.

public static toUpper([string $string = '' ]) : string

Uses mb_string extension if available.

Parameters
$string : string = ''

String that should be converted to uppercase

Return values
string

unique()

Chainable method for making any formatter unique.

public unique([bool $reset = false ][, int $maxRetries = 10000 ]) : UniqueGenerator
// will never return twice the same value $faker->unique()->randomElement(array(1, 2, 3));
Parameters
$reset : bool = false

If set to true, resets the list of existing values

$maxRetries : int = 10000

Maximum number of retries to find a unique value, After which an OverflowException is thrown.

Tags
throws
OverflowException

When no unique value can be found by iterating $maxRetries times

Return values
UniqueGenerator

A proxy class returning only non-existing values

valid()

Chainable method for forcing any formatter to return only valid values.

public valid([Closure $validator = null ][, int $maxRetries = 10000 ]) : ValidGenerator

The value validity is determined by a function passed as first argument.

$values = array(); $evenValidator = function ($digit) { return $digit % 2 === 0; }; for ($i=0; $i < 10; $i++) { $values []= $faker->valid($evenValidator)->randomDigit; } print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
Parameters
$validator : Closure = null

A function returning true for valid values

$maxRetries : int = 10000

Maximum number of retries to find a unique value, After which an OverflowException is thrown.

Tags
throws
OverflowException

When no valid value can be found by iterating $maxRetries times

Return values
ValidGenerator

A proxy class returning only valid values

appendEnd()

protected static appendEnd(mixed $text) : mixed
Parameters
$text : mixed

explode()

protected static explode(mixed $text) : mixed
Parameters
$text : mixed

generateText()

protected generateText(int $maxNbChars, array<string|int, mixed> $words) : string
Parameters
$maxNbChars : int
$words : array<string|int, mixed>
Return values
string

getConsecutiveWords()

protected getConsecutiveWords(mixed $indexSize) : mixed
Parameters
$indexSize : mixed

getExplodedText()

protected getExplodedText() : mixed

implode()

protected static implode(mixed $words) : mixed
Parameters
$words : mixed

strlen()

protected static strlen(mixed $text) : mixed
Parameters
$text : mixed

validStart()

protected static validStart(mixed $word) : mixed
Parameters
$word : mixed

replaceWildcard()

private static replaceWildcard(mixed $string, mixed $wildcard, mixed $callback) : mixed
Parameters
$string : mixed
$wildcard : mixed
$callback : mixed

        
On this page

Search results