Check Email Function PHP

Just recently created this piece of code for dream in codes new framework.

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
function check_email($email, $rec = 'MX'){
//	1. clean up email
	$email = trim($email);
 
	$v1 = strstr($email, ' ');
	if($v1 != null){
		echo 'There is a space.';
		return false;
	}
//	2. check if it has the proper characters
	list($start, $domain) = split("@", $email);
	if(isset($start) && isset($domain) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) > 0){
		echo  "good<br>";
 
		// 3. split email into two and check dns
		if(!empty($domain)) {
			if( $rec == '' ) $rec = "MX";
			exec("nslookup -type=$recType $hostName", $result);
			// check each line to find the one that starts with the host
			// name. If it exists then the function succeeded.
			foreach ($result as $line) {
				if(eregi("^$hostName",$line)) {
					echo "hostname is good";
					return true;
 
				}
		}
		// otherwise there was no mail handler for the domain
		return false;
	}return false;
    }return false;
}

The code isn’t exactly rocket science and thus I won’t be leaving you with any more information on this function.

Random Images Using A PHP Function: cj_random_image

Recently while working on a new blog layout for Code With Design I found myself finding that the code blocks look far to dull. My way of fixing this was to add an image but it didn’t end up helping anything, the image just looked repetitive and thus it is time to find some change and include a random image setup for each block.

WordPress uses a while loop to display the post information. I plan on taking advantage of this by adding a style to each of the div blocks. This will force the function to load for each div block and thus making the background images random for each individual block.

If the image was entered into the css then each block would look the same:

Function loads -> CSS is put into the style sheet -> style sheet loads into each element.

If the image was loaded on each div individually then the process will look something like this:

Function loads inside of div tag -> CSS is put into the looping div -> On each run the Function runs its random -> The random is placed out on each div.

The function loads a list of URL paths separated by comas. Then you are given the option of using placement properties and two of them so bottom right or top left is aloud. The final variable that this function uses is the repeat. This allows you to repeat the image by x, y, repeat or no-repeat.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
//'/images/br_corner_cloud.png,/images/tr_corner_cloud.png','bottom','right','no-repeat'
//creating a function
function cj_random_image($image_array, $prop1, $prop2, $repeat) {
//image arrays
$image_array = explode(",",$image_array);
 
$image_max = count($image_array);
//random image count based on user input
$image_rando = mt_rand(1, $image_max) - 1;
 
//image
echo 'url('.$image_array[$image_rando].')'.$prop1.' '.$prop2.' '.$repeat;
}
//created by calebj
?>

The first thing the function does is takes what the user has placed into it then outputs it. The main inputs are the URL paths. These paths are counted and the count is used as the maximum on the random. This forces the mt_rand function to return the proper value which means that you can enter any amount of image URLs and the function will still work out.

In order to use this effectively you will need to place the function like so:

1
2
3
<div style="background: #f2f2f2<?php cj_random_image('images/br_corner_cloud.png,images/cloud1.png','bottom','right','no-repeat'); ?> ">
 
</div>

If you would like to see this code working in action please click here. Keep in mind that you need to refresh the page to see the random clouds show up.

Intro to AS3: Using Mouse Events to Control an Object

Going through the code

View the results

For this creation we are first going to need event listeners in the project. An event listener is something that reacts when an event happens. So within the project we have a fade in and fade out button. Both of these buttons have event listeners that are given instructions on what to do when the event occurs. So in this example we are going to use the rotate left event listener which looks as follows.

rotate_left_btn.addEventListener(MouseEvent.MOUSE_DOWN, onRotateLeft);

This states that for the instance rotate_left_btn it will add an event listener and that event listener is a mouse event that will take place when the mouse button has been pressed down on. Then it will link to the onRotateLeft function.

//Functions for Rotation
function onRotateLeft(evt:MouseEvent):void {
box.rotation -= 10;
};

Note: Take note that information after two forward slashes is read as a comment and will not effect your code in any way. //Comments end when the line ends.

The function above declares that it is first a function then names it onRotationLeft. After naming the function the code will declare that this function has a mouse event then is posted as void. On the next line we state that we want there to be a left rotation so we use -=10;  then end the function with a closing bracket and a semicolon.

Later in the code we have some new mouse events and function that are not mouse buttons but drag actions with the mouse. Theses are created the same way that the other mouse buttons where, there is a function and an event listener but note the front of the event listener where we declare box at the beginning so it will only work when we click down and drag the box.

The Stage

What you will need on your stage is first a movie clip with an instance name of box. Now you will need the button images, these don’t need to be pretty they just need to be functional. The layout is up to you but if you need an example click the link before the action script code to view the SWF file.

The button instances are as follows:

move_left_btn
move_right_btn
move_up_btn
Move_down_btn

scale_up_btn
scale_down_btn

rotate_left_btn
rotate_right_btn

fade_in_btn
fade_out_btn

toggle_visible_btn

The Action script side of things

//Assigning movements with Functions
function onMoveLeft(evt:MouseEvent):void {
box.x -= 20;
};
function onMoveRight (evt:MouseEvent):void {
box.x += 20;Mouse Events: Controlling a Box
};
function onMoveUp(evt:MouseEvent):void {
box.y -= 10;
};
function onMoveDown (evt:MouseEvent):void {
box.y += 10;
};
//Move Mouse Events
move_left_btn.addEventListener(MouseEvent.MOUSE_DOWN, onMoveLeft);
move_right_btn.addEventListener(MouseEvent.MOUSE_DOWN, onMoveRight);
move_up_btn.addEventListener(MouseEvent.MOUSE_DOWN, onMoveUp);
move_down_btn.addEventListener(MouseEvent.MOUSE_DOWN, onMoveDown);
scale_up_btn.addEventListener(MouseEvent.MOUSE_DOWN, onScaleUp);
scale_down_btn.addEventListener(MouseEvent.MOUSE_DOWN, onScaleDown);
//Rotation Mouse Events
rotate_left_btn.addEventListener(MouseEvent.MOUSE_DOWN, onRotateLeft);
rotate_right_btn.addEventListener(MouseEvent.MOUSE_DOWN, onRotateRight);
//Fading Mouse Events
fade_in_btn.addEventListener(MouseEvent.MOUSE_DOWN, onFadeIn);
fade_out_btn.addEventListener(MouseEvent.MOUSE_DOWN, onFadeOut);
//Toggles the Visibility
toggle_visible_btn.addEventListener(MouseEvent.MOUSE_UP, onToggleVisible);
//Functions For Scaling
function onScaleUp(evt:MouseEvent):void {
box.scaleX += 0.1;
box.scaleY += 0.1;
};
function onScaleDown(evt:MouseEvent):void {
box.scaleX -= 0.1;
box.scaleY -= 0.1;
};
//Functions for Rotation
function onRotateLeft(evt:MouseEvent):void {
box.rotation -= 10;
};
function onRotateRight(evt:MouseEvent):void {
box.rotation += 10;
};
//Function For Fade in and Fade Out
function onFadeIn(evt:MouseEvent):void {
box.alpha += 0.1;
};
function onFadeOut (evt:MouseEvent):void {
box.alpha -= 0.1;
};
//Toggle Button to change Visibility
function onToggleVisible(evt:MouseEvent):void {
box.visible = !box.visible;
};
box.addEventListener(MouseEvent.MOUSE_DOWN,onStartDrag);
box.addEventListener(MouseEvent.MOUSE_UP,onStopDrag);
function onStartDrag(evt:MouseEvent):void {
evt.target.startDrag();
};
function onStopDrag(evt:MouseEvent):void {
evt.target.stopDrag();

};

Caleb Jonasson