*syl* --> [] | Coucou Voilà, j'suis un bleu en regexp c'est pkoi j'vous demande un petit coup de pouce Je voudrais faire une regexp qui prend du xhtml en entrée et qui vire tous les espaces, \t, \r, \n en dehors des balises..
Exemple bidon pour ceux qui ont pas compris :
<p>coin coin</p> <span id="plop">PlOp</span>
<p>coin coin</p> <span id="plop">PlOp</span> |
donne
<p>coin coin</p><span id="plop">PlOp</span><p>coin coin</p> <span id="plop">PlOp</span> |
J'ai maté un peu le source de Smarty (fichier Smarty_Compiler.class.php) mais euh.. Code :
- $compiled_content = '';
- /* Interleave the compiled contents and text blocks to get the final result. */
- for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
- if ($compiled_tags[$i] == '') {
- // tag result empty, remove first newline from following text block
- $text_blocks[$i+1] = preg_replace('!^(\r\n|\r|\n)!', '', $text_blocks[$i+1]);
- }
- $compiled_content .= $text_blocks[$i].$compiled_tags[$i];
- }
- $compiled_content .= $text_blocks[$i];
- /* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */
- if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $compiled_content, $_match)) {
- $strip_tags = $_match[0];
- $strip_tags_modified = preg_replace("!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", '', $strip_tags);
- $strip_tags_modified = preg_replace('![\r\n]+!m', '', $strip_tags_modified);
- for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++)
- $compiled_content = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s",
- $this->_quote_replace($strip_tags_modified[$i]),
- $compiled_content, 1);
- }
|
Voilà, donc si vous avez des idées/solutions, j'suis preneur  |