Last active
December 15, 2015 12:56
-
-
Save iksi/a11e775ab462ae5b1bac to your computer and use it in GitHub Desktop.
Imitation of Django’s spaceless tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* See https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#spaceless | |
* Removes whitespace between HTML tags. This includes tab characters and newlines. | |
* Only space between tags is removed – not space between tags and text. | |
* Single spaces between tags are preserved as they are probably intentional. | |
*/ | |
function spaceless($string) { | |
return preg_replace('/(?!>[ ]<)>\s+</i', '><', $string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment