Lasso Soft Inc. > Home

[RD_entityEncode]

LinkRD_entityEncode
AuthorWade Maxfield
CategoryString
Version8.x
LicensePublic Domain
Posted21 Aug 2008
Updated29 Aug 2008
More by this author...

Description

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;)

Sample Usage

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

email me


email me

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: '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

No comments

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