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); } 
  • @kiberchainik, According to the rules of the forum, questions should not be limited to solving or completing student assignments. Please clarify what you have done yourself and what did not work out. - Oleg Arkhipov

1 answer 1

You need to write a class in PHP to generate text for a given template

This is a forum where people communicate, communication begins with greeting lines, etc.

The most annoying thing is that you didn’t even bother to google a PHP class for generating texts using a given pattern

The very first link led to the answer with the solution of the same problem, solved back in 2012.

get an answer

I hope you get five. Have a nice day.