Sunday, September 18, 2011

Flex: Playing with text that contains HTML Entity

I was working and debugging projects with a bunch of test that contains HTML entities the other day and I realise that if you were given a bunch of copy that contains common HTML entities characters like '>', '<', '€', ... etc you might encounter problems like bold text not rendered correctly. And if you are going to filter or detect a special character in the body text, you might ended up checking for characters that contains &#...; if which quite troublesome and not so user friendly. Hence after looking around the web for some time, here is one of the derived solutions for some of the common special characters.


Here's the source file for the demo that I'm going to show in this post.


 
  
 
 
  
   
   
  
  
  
  
  
   
   
    
   
  
  
   
   
    
   
  
  
  
  
   
   
    
   
  
  
   
   
    
   
  
 


* Click here for the demo I have created.
^ Click here to download the source files for the demo.
# Click here for more information on HTML Entities.
! Click here for a better solution if you need a better and more complete class for replacing these HTML entities.

Thursday, September 8, 2011

Quick solutions to sending emails with PHP

I'm writing this post because there are things that I wouldn't want to forget. Even though PHP is a free and easy to use technology but I'm pretty sure that from time to time, there would be a need to generate and send out emails from your website. Therefore, this is one of the most useful solution that I had encountered before.


Introducing...

PHPMailer supports the following:
  • PHP 4,5,6
  • plain text and html encoded email messages... etc
  • Click here to find out more about the features that PHPMailer supports

Note: initially, I wanted to post a demo here but because most of the domains that I own were mainly free hosting domains... it makes it very troublesome to show a demo... Trust me, it will be much easier if you 'play' with PHPMailer on your personal php server. :)

* Click here for the website of PHPMailer.

Wednesday, August 31, 2011

Dynamic meta Description, meta Keywords and Title using PHP

Changing your the meta description, meta keywords and title of a php page.This is a follow up of a post that I had posted here a few weeks back.


I only make some changes to the header.php file and the header.php file will handle the value of $section and change the title, the meta description and meta keywords of the webpage.
<?
	//Conditional Statement to change the title, meta description and meta keywords.
	if ($section == "home"){
		$title = "Unique title for home page";
		$description = "A Unique description for 'Home' Section";
		$keyword = "Home";
	}else if ($section == "profile"){
		$title = "Special title for profile page";
		$description = "A Special description for 'Profile' Section";
		$keyword = "Profile";
	}else if ($section == "product"){
		//Another Conditional Statement to change the title, meta description and meta keywords base on the productID.
		$productID = $_REQUEST["productID"];
		if($productID == "x"){
			$title = "Product page for X";
			$description = "A description for 'Product X'";
			$keyword = "Product X";
		}else if($productID == "y"){
			$title = "Product page for Y";
			$description = "A description for 'Product Y'";
			$keyword = "Product Y";
		}else if($productID == "z"){
			$title = "Product page for Z";
			$description = "A description for 'Product Z'";
			$keyword = "Product Z";
		}else{
			$title = "A title for product page";
			$description = "A description for 'Product' Section";
			$keyword = "Product X, Product Y, Product Z";
		}
	}else if ($section == "contact"){
		$title = "Contact me now";
		$description = "Form for contact me";
		$keyword = "Conact me, form";
	}
	//Write the title, meta description and meta keywords into a header html tag
	echo "<header>";
	echo "<title>".$title."</title>";
	echo "<meta name='description' content='".$description."'>";
	echo "<meta name='keywords' content='".$keyword."' />"; 
	echo "</header>";
	//Create a table and base on the value os $section, toggle the state of the selected button.
	echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' ><tr>";
	//If $section == home, make the text 'Home' unclickable else makt it into a clickable hyperlink
	if ($section != "home"){
		echo "<td align='center'><a href='home.php'>Home</a></td>";
	}else{
		echo "<td align='center'><b>Home</b></td>";
	}
	//If $section == profile, make the text 'Profile' unclickable else makt it into a clickable hyperlink
	if ($section != "profile"){
		echo "<td align='center'><a href='profile.php'>Profile</a></td>";
	}else{
		echo "<td align='center'><b>Profile</b></td>";
	}
	//If $section == product, make the text 'Product' unclickable else makt it into a clickable hyperlink
	if ($section != "product"){
		echo "<td align='center'><a href='product.php'>Product</a></td>";
	}else{
		echo "<td align='center'><b>Product</b></td>";
	}
	//If $section == contact, make the text 'Contact Us' unclickable else makt it into a clickable hyperlink
	if ($section != "contact"){
		echo "<td align='center'><a href='contact.php'>Contact Us</a></td>";
	}else{
		echo "<td align='center'><b>Contact Us</b></td>";
	}
	echo "</tr></table>";
	echo "<br>";
?>

Click here for the example that I had created for the post.
Try click and copying the following URL1 and URL2 into Facebook and you will see how useful php can be.
Click here for the source codes of the example that I had created.

Friday, August 26, 2011

COMEX 2011

It's time to get ready for COMEX 2011. Time to catch a glimpse of the latest gadgets and at the same time get all the gadget at a promotional price. :P



Image taken form the COMEX website.

Details of COMEX 2011:
  • Venue: Level 1,2,3,4 and 6, Suntec City Convention Hall, Singapore
  • Date: 1st - 4th September 2011
  • Opening hours: 12noon - 9pm

* Click here for the website of COMEX 2011.

Wednesday, August 24, 2011

Flex: Measuring width of text of a Label

I have encounter a few situations in Flex where you need to position 2 labels side by side and the one on the left always ended up to be a dynamic label. If this is Flash, you can always use a .textWidth / .textHeight to solve the problem but in Flex, some of these properties were not available hence here's a workaround for it.



	
	
		Label{
			font-Size:20;
		}
	
	
		
	
	
	
		
		
			
		
		
			
		
		
			
		
		
			
		
		
		
			
			
		
	


Click here to view the demo.
Click here to download the source file of the demo.

Monday, August 22, 2011

Google Plus - Games Notification

Google Plus+ just added a new section for 'Games' recently. And as compared to the way how Facebook had organised the way game notifications were displayed, I love the way Google is displaying all the game notifications.


This is how Google Plus+ is doing it and I like it. Rather then messing up the feeds of my friends, they have created a seperate section for all these annoying 'Games Notifications'. This my friend is a +1 indeed. Though I still want a -1 button from Google Plus+. Can anyone help me to pass the message to Google asking them for a -1 button?

* Click here to access Google Plus+ website.
^ Click here to access Facebook.

Sunday, August 14, 2011

Flash / Flex AS3: Finding the difference between 2 dates

I have encounter numerous situation where there is a need to compare 2 different dates. I have created a simple example to demonstrate how to find out the difference between 2 dates.



	
		Days: " + tempArray[0] + "";
				outputTxt.htmlText += "
Hours: " + tempArray[1] + ""; outputTxt.htmlText += "
Minutes: " + tempArray[2] + ""; outputTxt.htmlText += "
Seconds: " + tempArray[3] + ""; outputTxt.htmlText += "
MilliSeconds: " + tempArray[4] + ""; } ]]>

package
{
	import mx.controls.DateField;
	import mx.controls.TextArea;

	public class TimeDifferenceMain
	{
		public function TimeDifferenceMain()
		{
		}
		
		public function compareDate(tempDate:Date):Array
		{
			//2 dates object: 1 is today's date, the other 1
			//is the selected date
			var now:Date = new Date();
			var selectedDate:Date = tempDate;
			
			//to store the difference of both dates in numerical value
			var remainder:Number;	
			
			//Store the number of milliseconds of both date since 1970
			var nowNum:Number = now.getTime();
			var selectedDateNum:Number = selectedDate.getTime();
			
			//Numbers to store number of milliseconds in eash day, 
			//each hour, each minute and each second
			var dayValue:Number = 24 * 60 * 60 * 1000;
			var hrValue:Number = 60 * 60 * 1000;
			var minValue:Number = 60 * 1000;
			var secValue:Number = 1000;
			
			//Compare which date is bigger and find the difference
			if(nowNum > selectedDateNum)
			{
				remainder = nowNum - selectedDateNum;	
			}else{
				remainder = selectedDateNum - nowNum;
			}
			
			//Modulas play a big role here as it is used to find
			//out the remainder of the next smaller unit
			var hrLeft:int = remainder % dayValue;
			dayValue = (remainder - hrLeft)/dayValue;
			var minLeft:int = hrLeft % hrValue;
			hrValue = (hrLeft - minLeft)/hrValue;
			var secLeft:int = minLeft % minValue;
			minValue = (minLeft - secLeft)/minValue;
			var milliSecLeft:int = secLeft % secValue;
			secValue = (secLeft - milliSecLeft)/secValue;
			
			//Create a array and store the output into the array
			var resultArray:Array = new Array();
			resultArray.push(dayValue);
			resultArray.push(hrValue);
			resultArray.push(minValue);
			resultArray.push(secValue);
			resultArray.push(milliSecLeft);
			return resultArray;
		}
	}
}

Click here to view the demo.
Click here to download the source file of the demo.