From: Ævar Arnfjörð Bjarmason Date: Mon, 7 Nov 2005 14:55:23 +0000 (+0000) Subject: * Trim the first and last newlines of strings passed via to avoid white... X-Git-Tag: 1.6.0~1208 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=81b9a6d8826ce35f5ae4e4a4f10ec09fbf37ac37;p=lhc%2Fweb%2Fwiklou.git * Trim the first and last newlines of strings passed via to avoid whitespace buildup --- diff --git a/includes/Parser.php b/includes/Parser.php index 6228154b08..9b5c593a1a 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2497,7 +2497,7 @@ class Parser preg_match_all( '/(.*?)<\/onlyinclude>/s', $text, $m ); $text = ''; foreach ($m[1] as $piece) - $text .= $piece; + $text .= $this->trimOnlyinclude( $piece ); } # Remove sections and tags $text = preg_replace( '/.*?<\/noinclude>/s', '', $text ); @@ -2572,6 +2572,19 @@ class Parser return $text; } } + + /** + * Trim the first and last newlines of a string, this is not equivalent + * to trim( $str, "\n" ) which would trim them all. + * + * @param string $str The string to trim + * @return string + */ + function trimOnlyinclude( $str ) { + $str = preg_replace( "/^\n/", '', $str ); + $str = preg_replace( "/\n$/", '', $str ); + return $str; + } /** * Translude an interwiki link.