fork download
  1. <?php // http://es.stackoverflow.com/q/22929/127
  2.  
  3.  
  4. function prefijarClasesYIds($css_file, $prefijo = '') {
  5. return preg_replace( '/[#.]\K(?=[a-z0-9][^{}]*+{)/i', $prefijo, $css_file);
  6. }
  7.  
  8.  
  9. // --- EJEMPLO ---
  10.  
  11. $css_file = "
  12. a:hover, a:visited, a.unId {
  13. prop: #aaa;
  14. }
  15.  
  16. body, #fff, a:link {
  17. prop: #bbb;
  18. }
  19.  
  20. .algun_id, #clase1, #clase2.otroId {
  21. prop: #ddd;
  22. }
  23. ";
  24.  
  25. $ejPrefijo = "PREFIJO";
  26. $css_file = prefijarClasesYIds( $css_file, $ejPrefijo);
  27.  
  28. echo $css_file;
  29.  
  30. ?>
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
				a:hover, a:visited, a.PREFIJOunId {
					prop: #aaa;
				}
				
				body, #PREFIJOfff, a:link {
					prop: #bbb;
				}
				
				.PREFIJOalgun_id, #PREFIJOclase1, #PREFIJOclase2.PREFIJOotroId {
					prop: #ddd;
				}