Advertisement
zero50x

Замены регуляками

Jul 13th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. // Замена в середине
  2. $text = "первое • второе";
  3. $text = preg_replace("/(?<=[а-яё:;,.])\s*•/ismu", " <br>•", $text);
  4.  
  5.  
  6. $text2 = "для мозга";
  7. $dva = "2";
  8. $text2 = preg_replace("/([а-яё]\sм)/ismu", "$1{$dva}", $text2);
  9.  
  10.  
  11. // Что бы работало без. доп. переменной надо так:
  12. $text2 = preg_replace("/([а-яё]\sм)/ismu", "\${1}2", $text2);
  13.  
  14. // Замена среднего элемента, крайние оставляем
  15. $contents = "<div id=\"test\"";
  16. $contents = preg_replace("/(<div\sid=\")(.*?)(\")/iu", "$1{$style2}$3", $contents);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement