Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
Improve StringHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMadness committed Aug 18, 2016
1 parent 99446f6 commit 6e8cf9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/StringHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,16 @@ public static function str2url($str)
$str = trim($str, "-");
return $str;
}

/**
* Minify string
*
* @param string $str
* @return string
*/
public static function minify($str)
{
return preg_replace(['/<!--(.*)-->/Uis', "/[[:blank:]]+/"], ['', ' '],
str_replace(["\n", "\r", "\t"], '', $str));
}
}
13 changes: 13 additions & 0 deletions tests/unit/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,17 @@ public function testXml2Array()
$this->assertEquals($xml,
\pwf\helpers\ConvertHelper::array2XML($result, 'root')->saveXML());
}

public function testStringMinifier()
{
$testString = "<html>
<test>test</test>
<!-- comment -->
</html>";
$result = '<html> <test>test</test> </html>';


$this->assertEquals($result,
\pwf\helpers\StringHelpers::minify($testString));
}
}

0 comments on commit 6e8cf9b

Please sign in to comment.