Hello good peoples, today I am going to show you how to generate same sentence unique each time action using PHP. Maybe, you already understand by seeing How to generate the same sentence unique every time using PHP and Latin character title. First, the question is why you should generate a unique sentence every time. The answer is I have developed SMS Server Software for my client to manage his business. He manages his customer's question and answers via this application by using logic like dialog flow. I have developed the logic system. He faced a problem that the sending provider and mobile operators blocks same message sending every time. He requested me to solve the problem so that I have developed the system that the system sends the same message every time with a unique style. For developing the system I had to use Latin characters. The Latin characters are used instead of the normal alphabet. So that I was collected the list of the Latin alphabet and process with my system. Let's go to the main point, our code.
First I have created a function for each alphabet replace to Latin. The function name is shh_latin_get() .This function will find the Latin alphabet of any character like a, b, c, d. Let's see the code of the function.
This function will return a Latin character for every normal character. Like for the character a the result will be like ā or ą or a̧ or ą̊. The result will be selected each time randomly by the built-in function shuffle() randomly because I stored a's multiple Latin characters in $a variable as an array. And the shuffle() function helps us to randomize the position of the character in the array. I've choosed the zero position using $character and returned it.
Now it's time to work with a full sentence. For that, I have to create another function to reduce code complexity. I have created a new function name as shh_convert_latin() and this function will help us to process convert system for a full sentence. Let's write the code and after this, I will explain it.
In this function, I explode every word of a sentence and chose a character randomly from the word and replace it with our previous build shh_latin_get() function and then combine the sentence again. If you see the code you will clear it. Now we will choose our sentence and run it with the function. Suppose we choose a sentence,
My momma always said, “Life was like a box of chocolates. You never know what you're gonna get.”
Now, will run this sentence with the function we have created. Let's see the first time result.
Number - 1
Mý mommā alŵays sai̧d, “Lįfe waş łike ā bôx oƒ çhoçolates. Yȱu nȩvȩr knoŵ wha̧t yoų're gonną̊ gȩt.”
Number - 2
My m̧om̧m̧a ałways saɨ̧d, “Lifę waś łike ą bōx òf chocolatȩs. Yôu neveɍ knǒw wħat you'rȩ goṅṅa get.”
Number - 3
Mý mõmma alwayš sai̧d, “Life wās łike ą ɓox óf chȭcȭlates. Yoů nęvęr knoẅ ẅhat yoû're gonną̊ get.”
Number - 4
My m̧om̧m̧a alwayṣ saiđ, “Lɨ̧fe waş łike a̧ box ơf chocołates. Yoű nȩvȩr knoẅ ŵhat you'rę ɠonna ɠet.”
Number - 5
Mỳ mommā ālwāys ṣaid, “Life waṡ łike ą box ȯf çhoçolates. Yoů never knŏw wɦat you'rę goñña get.”
See, the system created new sentences each time in my 5 results. The sentence is the same but words are replaced with special characters. So that any system will count each system as a new sentence. We have created unique sentences successfully. Though the code is a little bit of complicated but the system is awesome and helpful. I hope you understand this if you have any question on this you can ask me directly via comment. Have a good time, Happy coding. Bye!