piterskiy

Заменить каждое вхождение

Oct 9th, 2017
25,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #заменит каждое вхождение «REPLACEMENT» на случайное слово из файла keys.txt
  2. <?php
  3.  
  4. $keys = file('keys.txt');
  5. shuffle($keys);
  6.  
  7. $template = file_get_contents('template.txt');
  8.  
  9. foreach ($keys as $key) {
  10.     $template = preg_replace("#REPLACEMENT#Uuis", trim($key), $template, 1);
  11. }
  12.  
  13. echo $template;
Advertisement
Add Comment
Please, Sign In to add comment