Friday, August 29, 2008

SPAW Editor - Free web based in-browser WYSIWYG editor for php and .net

SPAW Editor is a Free web based in-browser WYSIWYG editor.
Very good features and fully customizable and has support for both php and .net
very easy and simple to integrate into the site.
This tool is great to build a Content Management System(CMS) for you site.



SPAW Editor


Get custom programming done at GetAFreelancer.com!

Wednesday, August 27, 2008

How to convert Unix Timestamp to Mysql Timestamp - Time() to String using php

If you want to convert the Unix timestamp into a string like mysql timestamp you can take a look at following code. Unix timestamp is not human readable so there are situations where you need to convert it into a human readable form.


<?php

$time_now = time();

echo $time_now; //output example: 1219848654
echo '<br />';

$str_time = date('Y-m-d H:i:s', $time_now);

//look at php date function for more options

echo $str_time; // 2008-08-27 14:50:54

?>


Get Free Sinhala IT Learning Videos Kuppiya.com



Get custom programming done at GetAFreelancer.com!

Tuesday, August 26, 2008

how to get a specific row in a large result set in mysql using php

When you work with a large result set you may need to get a specific row from the result set. When in a such situation you can use mysql_result().


$result = mysql_query('SELECT * FROM tbl_name');
echo mysql_result($result, 5); // output 6th row


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Sunday, August 24, 2008

How to remove first letter from a string using php - substr()

When you need to strip or remove the first letter from a string, the easiest way to do it is to use php substr(). you can use substr() for many purposes look at the php manual here

<?php

$my_text = '12345678';

echo substr($my_text, 1);  // 2345678

?>



Get custom programming done at GetAFreelancer.com!

Thursday, August 21, 2008

How to redirect a page using java script - window.location

when you need to redirect a web page using JavaScript you can easily use window.location to redirect a page to anther web page.
Check out the following code


<HEAD>
<SCRIPT language="JavaScript">
<!--
window.location="http://yourURL.com";
//-->
</SCRIPT>
</HEAD>



Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Wednesday, August 20, 2008

How to get current executing file in php

When you need to get the currently executing php script, you can use $_SERVER["SCRIPT_NAME"] to get the full path of the executing file, then you can easily explode the returned string and get the file name only.
Look at the code below


<?php

//get current executing page
//you get the full directory path
//ex: /test/path.php

$file_path = $_SERVER["SCRIPT_NAME"];

//so we expolde it into an array
$parts = Explode('/', $file_path);

//need to get the last element from array
$file_name = $parts[count($parts) - 1];

echo $file_name; //path.php

?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Tuesday, August 19, 2008

How to get Max ID row from mysql table using php

Do you need to find the max id of a mysql table? check out the following code.
simply use the sql MAX function to find the max id.

<?php

mysql_connect("localhost","root","");
mysql_select_db(test);

$q = "select MAX(id) from tbl_name";
$result = mysql_query($q);
$data = mysql_fetch_array($result);

echo $data[0];

?>


Friday, August 15, 2008

How to check if a array key exists in php - array_key_exists()

when writing code using arrays you'll probably found stuck on a situation where you loose track of array keys in a associate array, or maybe its random that you don't know if its there or not.


if (array_key_exists('key_name', $search_array))
{
echo "array key found";
}


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Thursday, August 14, 2008

How to open a PDF inside a php file - Restrict access to pdf files using php

Following code will show you how to open a pdf file inside a php file. This will allow you to restrict access to it. you can use some if else logic to control to display who see the pdf or who does not.


<?php

//you can get data from database in here
$user = 'some value';

if($user == 'some value')
{
$file = "test.pdf";
header('Content-type: application/pdf');
header("Content-Disposition: inline; filename=".$file);

//this line will make the file directly download
/* header("Content-Disposition: attachment; filename=".$file); */

header('Cache-control: private');
header('Expires: 0');
readfile($file);
}
else
{
echo 'you cannot access this file';
}
?>


Get Free Sinhala IT Learning Videos Kuppiya.com



Get custom programming done at GetAFreelancer.com!

Wednesday, August 13, 2008

Sunday, August 10, 2008

How Mysql TIME data type works with php

Lets see what is the format that is accepted by Mysql TIME data type.
Normal format: HH:MM:SS
Extended hour format: HHH:MM:SS - This is larger than 23 hours because its used to store time between two points.

It's better if you use above formats to store your time manually


INSERT INTO your_tbl VALUES ('14:26:05')



Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Friday, August 8, 2008

How to replace a string within given portion - substr_replace()

When you need to replace a text in a given portion of string you can use substr_replace()
For example if you want to change the

here are some examples : http://www.php.net/substr_replace


Get custom programming done at GetAFreelancer.com!

Sunday, August 3, 2008

Trouble submitting a form using a image type button? Use hidden field

Trouble submitting a form using a image type button?
Image type button sometimes not work with POST method in IE,
Easiest way to overcome this is to set a hidden field and check that in your php code


<?php

if(isset($_POST['sub']))
{
//do somthing
}
?>

<form name="form1" method="POST" action="">
<input type="image" src"..." />
<input type="hidden" name="sub" value="sub" />
</form>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Friday, August 1, 2008

How to get the date from MySql TIMESTAMP column using php

In mysql you can use a TIMESTAMP type to store both date and time in a table column in this format YYYY-MM-DD HH:MM:SS
Sometimes you need to get only the date part from the TIMESTAMP.
You can use mysql date() function to do this


<?php

$today = date("Y-m-d"); //todays date

$query = "select * from tbl where DATE(c_timstp) = $today";

$result = mysql_query($query);

?>



Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!