Last active
January 4, 2022 10:38
Revisions
-
mcaskill revised this gist
Nov 24, 2017 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ { "name": "mcaskill/php-strip-html", "description": "Strip HTML and PHP tags from a string.", "license": "MIT", "authors": [ @@ -13,6 +12,11 @@ "keywords": [ "function" ], "extra": { "branch-alias": { "dev-master": "1.x-dev" } }, "require": { "php": ">=5.4.0" }, -
mcaskill revised this gist
Feb 23, 2017 . 3 changed files with 7 additions and 19 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ <?php if (!function_exists('strip_html')) { /** * Strip HTML and PHP tags from a string. * * @param string $str The input string. * @return string Returns the stripped string. */ function strip_html($str) { $str = html_entity_decode($str); @@ -38,4 +38,4 @@ function strip_html( $str ) return $str; } } This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -29,20 +29,6 @@ Returns the stripped string. $ composer require mcaskill/php-strip-html ``` ### Without Composer Why are you not using [composer](http://getcomposer.org/)? Download `Function.Strip-HTML.php` from the gist and save the file into your project path somewhere. This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ { "name": "mcaskill/php-strip-html", "version": "1.0.0", "description": "Strip HTML and PHP tags from a string.", "license": "MIT", "authors": [ { "name": "Chauncey McAskill", -
mcaskill created this gist
May 31, 2016 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ <?php if ( ! function_exists('strip_html') ) : /** * Strip HTML and PHP tags from a string. * * @param string $str The input string. * @return string Returns the stripped string. */ function strip_html( $str ) { $str = html_entity_decode($str); // Strip HTML $str = preg_replace('#<br[^>]*?>#siu', "\n", $str); $str = preg_replace( [ '#<head[^>]*?>.*?</head>#siu', '#<style[^>]*?>.*?</style>#siu', '#<script[^>]*?.*?</script>#siu', '#<object[^>]*?.*?</object>#siu', '#<embed[^>]*?.*?</embed>#siu', '#<applet[^>]*?.*?</applet>#siu', '#<noframes[^>]*?.*?</noframes>#siu', '#<noscript[^>]*?.*?</noscript>#siu', '#<noembed[^>]*?.*?</noembed>#siu' ], '', $str ); $str = strip_tags($str); // Trim whitespace $str = str_replace("\t", '', $str); $str = preg_replace('#\n\r|\r\n#', "\n", $str); $str = preg_replace('#\n{3,}#', "\n\n", $str); $str = trim($str); return $str; } endif; This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ # strip_html (PHP 5 >= 5.4) `strip_html` — Strip HTML and PHP tags from a string. ## Description ```php string strip_html( string $str ) ``` This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given `str`. Unlike [`strip_tags()`](https://php.net/strip-tags), this function is mindful of line-breaks and metadata elements (e.g., `<style>`). This function is useful for converting a HTML-rich string into a plain-text string for emails. ## Parameters - `str` — The input string. ## Return Values Returns the stripped string. ## Installation ### With Composer ``` $ composer require mcaskill/php-strip-html ``` ```json { "repositories": [ { "type": "git", "url": "https://gist.github.com/***.git" } ], "require": { "mcaskill/php-strip-html": "dev-master" } } ``` ### Without Composer Why are you not using [composer](http://getcomposer.org/)? Download `Function.Strip-HTML.php` from the gist and save the file into your project path somewhere. This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ { "name": "mcaskill/php-strip-html", "description": "Strip HTML and PHP tags from a string.", "authors": [ { "name": "Chauncey McAskill", "email": "chauncey@mcaskill.ca", "homepage": "https://github.com/mcaskill" } ], "keywords": [ "function" ], "require": { "php": ">=5.4.0" }, "autoload": { "files": ["Function.Strip-HTML.php"] } }