Hello.
Here, for example, is a variable with the text “Hi% s. Welcome to% s. And% s for you. ”
How to replace% s with the words I need.
There is a list of the words "user", "site", "have a nice day."
And after replacing the variable, there should already be such text:
“Hello user. Welcome to the site. And have a nice day. ”

Thank you in advance.

    2 answers 2

    Hey. You can like this:

    $str = 'Привет %s. Добро пожаловать на %s. И %s тебе.'; $name = 'Вася'; $site = 'www.xxx.com'; $hi = 'доброго дня'; $str = sprintf($str, $name, $site, $hi); // Выведем строку для просмотра результата echo $str; 

    This is just an example, and then you can implement as you please.

    • What you need! Thanks :) - The Blogaster

    It is possible so:

     $arr1 = array("Привет %s", "Добро пожаловать на %s", "И %s тебе"); $arr2 = array("юзер", "сайт", "хорошего дня"); for($i = 0;$i<=count($arr1)-1;$i++) $text[$i] = str_replace("%s",$arr2[$i], $arr1[$i]); echo($text[0])."<br>"; echo($text[1])."<br>"; echo($text[2]); 
    • Thank. Can this be the only way or is there a special function in PHP? - Blogaster