ezequielg 1 Denunciar post Postado Dezembro 6, 2011 Bom dia! Preciso converter a função abaixo de "ereg_replace" para "preg_match", mas não estou dando jeito. function strip_php_comments(&$str) { $str = str_replace("<?php", '<?php ', $str); $str = str_replace("\r", '', $str); $str = ereg_replace("/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", '', $str); $str = ereg_replace("//[\x20-\x7E]*\n", '', $str); $str = ereg_replace("#[\x20-\x7E]*\n", '', $str); $str = ereg_replace("\t|\n", '', $str); } Agradeço a quem puder ajudar Compartilhar este post Link para o post Compartilhar em outros sites
Matheus Tavares 167 Denunciar post Postado Dezembro 6, 2011 <?php function strip_php_comments(&$str) { $str = str_replace("<?php", '<?php ', $str); $str = str_replace("\r", '', $str); $str = preg_replace("//\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+//", '', $str); $str = preg_replace("///[\x20-\x7E]*\n/", '', $str); $str = preg_replace("/#[\x20-\x7E]*\n/", '', $str); $str = preg_replace("/\t|\n/", '', $str); } Acho q é isso... dá pra melhorar mais, colocar em arrays, enfim.. Compartilhar este post Link para o post Compartilhar em outros sites
ezequielg 1 Denunciar post Postado Dezembro 6, 2011 Matheus, obrigado pela rápida resposta, fiquei impressionado com a rapidez aqui. Velho, também tentei colocar a barra no início e fim, mas exibe o sequinte erro "Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' in /home/geral/lyon_alimentos/PHPCodeCompressor.php on line 16" Abaixo a função completa para entender <?php /** * PHP Code compressor * * @author Piotr Polak * @version 0.1 * @license see http://www.polak.ro/licencing-projects.html * @link http://www.polak.ro/php-code-compressor.html */ function strip_php_comments(&$str) { $str = str_replace("<?php", '<?php ', $str); $str = str_replace("\r", '', $str); $str = preg_replace("//\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+//", '', $str); $str = preg_replace("///[\x20-\x7E]*\n/", '', $str); $str = preg_replace("/#[\x20-\x7E]*\n/", '', $str); $str = preg_replace("/\t|\n/", '', $str); } function cc_files($path = '', $destination = './output/') { if($path == '' || $path == './') return; @mkdir($destination); $dir = opendir($path); while($file = readdir($dir)) { if($file == '' || $file == '.' || $file == '..') continue; if(is_dir($path.'/'.$file)) { cc_files($path.'/'.$file, $destination.'/'.$file.'/'); } else { // for files $contents = file_get_contents($path.'/'.$file); if(strtolower(substr($file, strrpos($file, '.')+1)) == 'php') { strip_php_comments($contents); } file_put_contents($destination.'/'.$file, $contents); } } } cc_files('./web/', './output'); ?> O código é deste autor: http://www.polak.ro/php-code-compressor.html É uma função para comprimir arquivos. Compartilhar este post Link para o post Compartilhar em outros sites
Matheus Tavares 167 Denunciar post Postado Dezembro 6, 2011 E assim? $str = preg_replace("/\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\//", '', $str); $str = preg_replace("/\/\/[\x20-\x7E]*\n/", '', $str); $str = preg_replace("/#[\x20-\x7E]*\n/", '', $str); $str = preg_replace("/\t|\n/", '', $str); Compartilhar este post Link para o post Compartilhar em outros sites
ezequielg 1 Denunciar post Postado Dezembro 6, 2011 Muito obrigado! Não exibiu mais erro algum. Abração! Compartilhar este post Link para o post Compartilhar em outros sites