[RD_entityEncode]

Description

Link: [RD_entityEncode]
Author: Wade Maxfield
Category: String
Version: 8.x
License: Public Domain
Posted: Aug. 21, 2008
Updated: Aug. 29, 2008
More by this author...

Entity encodes the supplied string using decimal, hexadecimal, or a random mix. Useful for obfuscating email addresses or phone numbers from web crawling spam bots. Tested with 8.5.x but should work with 8.x or even earlier.

Be sure to use the "Download This Tag" link, and not just copy and paste it from the textarea. The last 2 lines appear as:

#encodedString->(Replace: ':', ':');
#encodedString->(Replace: ':', ':');

in a browser, but in the tag file they are HTML entities instead (#58; #x3a;)

Parameters

-theString string, required The string to encode
-method string, optional Which method to use (decimal, hexadecimal or a random mix)

Sample Usage

Variable: 'theEmail' = (RD_entityEncode: 'mailto:test@test.com', -method='random');

<a href="[$theEmail]">email me</a>


<a href="[RD_entityEncode: 'mailto:test@test.com', -method='random', -EncodeNone]">email me</a>
						

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
47
48
49
50
51
52
53
54
55
56
Define_Tag: 'entityEncode',
	-Namespace='RD_',
	-Required='theString',
	-Optional='method',
	-ReturnType='String';

	Local: 'encodedString' = String;
	Local: 'c', 'h' = String;
	Local: 'i', 'r' = Integer;

	If: !(Local_Defined: 'method');
		Local: 'method' = 'decimal';
	/if;

	Select: #method;
		Case: 'decimal';
			Iterate: #theString, #c;
				#i = #c->(Integer);
			    #encodedString += '&#' + #i + ';';
			/Iterate;
		
		Case: 'hexadecimal';
			Iterate: #theString, #c;
				#i = #c->(Integer);
				#i->(SetFormat: -Hexadecimal=True);
				#h = (String: #i);
				#h->(RemoveLeading: '0');
				#encodedString += '&#' + #h + ';';
			/Iterate;

		Case: 'random';
			Iterate: #theString, #c;
				#r = (Math_Random: -Lower=1, -Upper=100) % 7;
				Select: #r;
					Case: (#r < 3);
						#encodedString += (RD_entityEncode: #c, -method='decimal');
						
					Case: 3;
						#encodedString += #c;
					
					Case: (#r > 3);
						#encodedString += (RD_entityEncode: #c, -method='hexadecimal');

				/Select;
			/Iterate;
		
	/Select;
	
	// convert : back to plain ASCII
	// in order to play nice with browsers when encoding mailto:xxx@yyy.com style links
	#encodedString->(Replace: ':', ':');
	#encodedString->(Replace: ':', ':');
	
	Return: #encodedString;
	
/Define_Tag;

 

Comments

none

Email:


Password:



Newest

Most Popular