Tag Archive for txt

AS3 Load External Text File

package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class Main extends MovieClip
	{
		private var _txtFileToLoad:String = "myTextFile.txt";
		private var _txtLoader:URLLoader;
		private var _loadedTxt:String;
		

		public function Main():void
		{
			loadExternalTxtFile();
		}
		
		private function loadExternalTxtFile():void
		{
			_txtLoader = new URLLoader();
			_txtLoader.addEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.addEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			_txtLoader.load(new URLRequest(_txtFileToLoad));
		}
		
		private function onTxtLoader_COMPLETE(event:Event):void {
			_txtLoader.removeEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.removeEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			_loadedTxt = String(event.target.data);
			trace(_loadedTxt);
		}
		
		private function onTxtLoader_IO_ERROR(event:Event):void {
			_txtLoader.removeEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.removeEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			trace(event.target.text);
		}

	}
}

source

loading an external txt file

private function loadDictionary(path:String):void {
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE,dictionaryLoaded);
loader.load(new URLRequest(path));
}

source

Get the length of a string on the command line with Ruby

ruby -e "puts 'length of this string'.length"

source

Send Mail Function (HTML TXT)

<?php
function send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body)
{
$eol="
";
$mime_boundary=md5(time());

# Common Headers
$headers .= "From: $namefrom <$fromaddress>".$eol;
$headers .= "Reply-To: $namefrom <$fromaddress>".$eol;
$headers .= "Return-Path: $namefrom <$fromaddress>".$eol;
// these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters

# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary="".$mime_boundary.""".$eol;

$msg = "";


# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;

# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= strip_tags(str_replace("<br>", "
", $body)).$eol.$eol;

# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;

# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.

# SEND THE EMAIL
// ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);

//  ini_restore(sendmail_from);
//  echo "mail send";
return 1;
}

?>

source

basic hit counter

<?php
//tutorial for text-file based counter
$counthandle=fopen("visits2.txt","r");
//opens file for reading and writing
$getcurrent=fread($counthandle,filesize("visits2.txt"));
//reads in current value
$getcurrent=$getcurrent+1;
//increment count by 1
fclose($counthandle);
$counthandle1=fopen("visits2.txt","w");
fputs($counthandle1,$getcurrent);
//input new value
fclose($counthandle1);
$counthandle2=fopen("visits2.txt","r");
$getrecent=fread($counthandle2,filesize("visits2.txt"));
//gets new value
//print "$getrecent";
//print counter value
fclose($counthandle2);
?>

source