Archive

Posts Tagged ‘PHP’

Secret of PHP Echo

November 6th, 2008

For example you want to echo several part of strings, usually we use this
<?php echo ‘hello ‘.’ world ‘.$name; ?>

I read some articles that using comma such as <?php echo ‘hello ‘,’ world ‘.$name; ?> is faster than string concatenation with dot.
Read more…

PHP

Simple PHP Template

October 29th, 2008

Most PHP programmers use template technique on page design. When do you need template for your script? If in most pages the design looks same except on some part (for example the content or “middle” part), you might need a template technique. Lets look for these examples
Read more…

PHP, Programming

Little PHP Cheat

October 7th, 2008

Here is a little PHP cheat from me :D

To generate an array of (’a', ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’), you only need to do this :
<?php $array_of_char = str_split('abcdefg'); ?>

To generate an array of (1, 2, 3, 4, 5, 6, 7, 8, 9), you only need to do this
<?php $array_of_num = range(1, 9); ?>

Now cheating is fun ( cheating in PHP of course :D )

PHP, Programming

PHP Database Helper Class

September 20th, 2008

Usually we have edit and insert page for administration area.

While constructing the SQL query for editing and inserting for a same table with lots of fields may consume lot of time, why don’t we make it easier ?

So i create this class to help you with construction the SQL query for editing and inserting data.

Here’s the example usage of editing query

$dh = new dbhelper();
$dh->table_name = 'bet_type';
$dh->setFields(
   array('name' => 'bet_type_name', 'value' => $bt_name),
   array('name' => 'minimum_bet', 'value' => $bt_minimum_bet, 'type' => 'int'),
   array('name' => 'maximum_bet', 'value' => $bt_maximum_bet, 'type' => 'int'),
   array('name' => 'prize_percentage', 'value' => $bt_prize_percentage, 'type' => 'int'),
   array('name' => 'choice_length', 'value' => $bt_choice_length, 'type' => 'int'),
   array('name' => 'bet_note', 'value' => $bt_note),
   array('name' => 'bet_link_note', 'value' => $bt_link_note),
   array('name' => 'bet_type_status', 'value' => $bt_status),
   array('name' => 'sort_order', 'value' => $bt_sort_order, 'type' => 'int')
);
$q = $dh->sqlUpdate();
mysql_query($q);

Read more…

PHP, Programming

Cloak The Mail

September 11th, 2008

I created a function recently. This function will insert random hidden spans between e-mail address that wil be displayed to the user. The purpose is to protect the e-mail from the crawler. I know this function may be does not powerful enough to prevent crawlers. :D By the way here is the function

/**
* Randomize email, insert hidden span randomly between e-mail address
* to prevent crawler.
*
* @arg        string    $email    the e-mail
* @return    string    scrambled e-mail (with HTML code)
*/
function randomizeEmail($email) {
	$s = $email;
	if ($email != '') {
		$s = '';
		$length = strlen($email);
		$random = str_split($email, ceil($length / mt_rand(2, ceil(0.8 * $length))));
		foreach ($random as $r) {
			$s .= $r.'<span style="display:none">'.md5(microtime()).'</span>';
		}
	}
	return $s;
}

PHP, Programming