Code is Poetry
Tuesday, August 10, 2010
Create RSS Feed in php
Well here is script in php which generate RSS feed from database .
Saturday, April 24, 2010
Finding slow part of your php code
In which function or method execution is very slow.
Here is a little code which check the speed of your php script,
Define this function on top of your script or in any other file and include that in your page,
<?php function speedcheck() {
static $str = NULL;
if( is_null($str) ) {
$str = microtime();
} else {
$speedcheck = microtime() - $str;
$str = microtime();
return $speedcheck;
}
}
function microtime() {
list($uses, $second) = explode(" ", microtime());
return ((float)$uses + (float)$second);
} ?>
After that call this function after execution of your function and methods, this will return the execution time. and then you check performance of your code.
<?php
speedcheck(); /* The first call will initialize the function */
/* Some code */
echo speedcheck() .'<br />';
/* Some more code */
echo speedcheck() .'<br />';
/* Yet more code */
echo speedcheck() .'<br />'; ?>
Tuesday, April 20, 2010
play with source code
Well we can see actual code also with a single php function.
here is an example . Check it out this simple script.
<?php
if ( isset( $_POST['file'] ) )
show_source( $_POST['file'] ) or print "can not be open \"$file\"";
?>
<html>
<head>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
Enter file name:
<input type="text" name="file" value="<?php print $file; ?>">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Saturday, April 17, 2010
create thumbnail of an image
Here is code to create thumbnail for any image, you have to only pass source of the image, destination where you want to store the thumbnail and desired width of the thumbnail.
//Developed by Dileep
function create_thumb($src,$dest,$setwidth)
{
/* source image */
$source = imagecreatefromjpeg($src);
$width = imagesx($source);
$height = imagesy($source);
/* find the height of this thumbnail, relative to the width */
$setheight = floor($height*($setwidth/$width));
/* creation of new image */
$img = imagecreatetruecolor($setwidth,$setheight);
/* copy source image at a resized size */
imagecopyresized($img,$source,0,0,0,0,$setwidth,$setheight,$width,$height);
/* create the physical thumbnail image to its destination */
imagejpeg($img,$dest);
}
?>
Cheers,
Happy Coding ...
Share with orkut from your webpage
<div id="orkut-button"></div>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('orkut.share', '1');
google.setOnLoadCallback(function() {
new google.orkut.share.Button({
summary: 'So much to see here.'
}).draw('orkut-button');
});
</script>
Cheers ..
Happy Coding
Friday, April 9, 2010
Retrieve data from other website
PHP comes with a lot of file functions to read , write and perform various function from the hard drive, same if you want to find data from web not from hard drive or simply you can say that find data from third party then use cURL . Various hosting companies disable them for security reasons. Dont worry you can start cURL on your server by little change in php.ini file on your localhost server. Remove ';' sign from ';extension=php_curl.dll' in your php.ini file.
Well now you are ready to implement a killing application
cURL makes a HTTP request to retrieve information.
Hey I am giving here a very simple example to understand better
// We will load this url on our page
$url = 'http://www.google.co.in';
// now start cURL
$ch = curl_init();
// tell cURL about the URL
curl_setopt($ch, CURLOPT_URL, $url);
// tell cURL that you want the data back from that URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// run cURL
$output = curl_exec($ch);
// end the cURL call (it will cleans up memory
curl_close($ch);
// display the output
echo $output;
?>
Check this little code on your local server or any web server.
Will back soon with new killing application..
Happy Coding..