You need to write a class in PHP to generate texts for a given template.
In a class there should be a public function that transfers 1 parameter - a template. This function should return the generated text.
Template example: (Hello | Good afternoon), Eugene. (| Today (beautiful | bad | terrible) weather, isn't it? | How do you (do you | do you feel)?)
In parentheses (groups) phrases are separated by the symbol |. One random phrase is selected from the group. Groups can contain an unlimited number of subgroups. Thus, from the sample template, only the following phrases can be obtained: - Hello, Eugene. - Good afternoon, Eugene. - Hello, Eugene. Today is a beautiful weather, isn't it? - Good afternoon, Eugene. How are you? etc.
I don’t understand how to do this ... here’s what I’ve got:
class TZ { public function shablon ($name, $text) { $shablon = explode(",", $name); foreach ($shablon as $key => $value) { echo "Привет ".$value."<br />"; } } } $tz = new TZ; if (isset($_POST['go'])){ $name = htmlspecialchars($_POST['name']); $text = htmlspecialchars($_POST['text']); $tz->shablon($name, $text); }