Lasso Soft Inc. > Home

[string_removehtml]

Linkstring_removehtml
AuthorJason Huck
CategoryString
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted29 Nov 2005
Updated16 Jan 2007
More by this author...

Description

Strips all HTML tags from the given string. Attempts to preserve some formatting.

Sample Usage

var('testdata') = string(include_url('http://tagswap.net/'));	
'
' + string_removehtml($testdata) + '
';

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'removehtml',
	-namespace='string_',
	-priority='replace',
	-required='text',
	-type='string',
	-optional='linebreak',
	-type='string',
	-description='Strips HTML tags from the given string. Attempts to preserve some formatting.'
);	
	local('out') = params->first;
	!local_defined('linebreak') ? local('linebreak' = '\n');

	#out = string_replaceregexp(
		#out,
		-find='\\s+',
		-replace=' ',
		-ignorecase
	);

	#out = string_replaceregexp(
		#out,
		-find='(?s)',
		-replace=#linebreak,
		-ignorecase
	);

	#out = string_replaceregexp(
		#out,
		-find='(?s)',
		-replace=(#linebreak * 2),
		-ignorecase
	);

	#out = string_replaceregexp(
		#out,
		-find='(?s)<.+?>',
		-replace='',
		-ignorecase
	);

	#out = decode_html(#out);

	return(@#out);
/define_tag;

Related Tags

Comments

19 Jul 2006, Johan Solve

Case sensitive

The <p&grt; and <br> replacements should be case insensitive. Either change (?s) into (?si) in the regex pattern or add -ignorecase at the endf of the string_replaceregexp tags.

19 Jul 2006, Johan Solve

Case sensitive

The

and
replacements should be case insensitive. Either change (?s) into (?si) in the regex pattern or add -ignorecase at the endf of the string_replaceregexp tags.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft