[string_removehtml]

Description

Link: [string_removehtml]
Author: Jason Huck
Category: String
Version: 8.x
License:
Posted: Nov. 29, 2005
Updated: Jan. 16, 2007
More by this author...
Strips all HTML tags from the given string. Attempts to preserve some formatting.

Parameters

-text string, required The text to be stripped.
-linebreak string, optional The linebreak style to use. Defaults to unix (

Sample Usage

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

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)<br.+?>',
		-replace=#linebreak,
		-ignorecase
	);

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

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

	#out = decode_html(#out);

	return(@#out);
/define_tag;

 

Related Tags



Comments

07/19/2006, Johan Sölve
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.
07/19/2006, Johan Sölve
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.

Email:


Password:



Newest

Most Popular