• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/outputfilter.trimwhitespace.php

00001 <?php
00028 function smarty_outputfilter_trimwhitespace($source, &$smarty)
00029 {
00030     // Pull out the script blocks
00031     preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
00032     $_script_blocks = $match[0];
00033     $source = preg_replace("!<script[^>]+>.*?</script>!is",
00034                            '@@@SMARTY:TRIM:SCRIPT@@@', $source);
00035 
00036     // Pull out the pre blocks
00037     preg_match_all("!<pre>.*?</pre>!is", $source, $match);
00038     $_pre_blocks = $match[0];
00039     $source = preg_replace("!<pre>.*?</pre>!is",
00040                            '@@@SMARTY:TRIM:PRE@@@', $source);
00041 
00042     // Pull out the textarea blocks
00043     preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
00044     $_textarea_blocks = $match[0];
00045     $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",
00046                            '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
00047 
00048     // remove all leading spaces, tabs and carriage returns NOT
00049     // preceeded by a php close tag.
00050     $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
00051 
00052     // replace script blocks
00053     smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
00054 
00055     // replace pre blocks
00056     smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
00057 
00058     // replace textarea blocks
00059     smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
00060 
00061     return $source;
00062 }
00063 
00064 function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
00065     $_len = strlen($search_str);
00066     $_pos = 0;
00067     for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
00068         if (($_pos=strpos($subject, $search_str, $_pos))!==false)
00069             $subject = substr_replace($subject, $replace[$_i], $_pos, $_len);
00070         else
00071             break;
00072 
00073 }
00074 
00075 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2