Friday, August 17, 2007

Php installation in windows/Linux etc...

These are some method to install apahe/php/mysql/phpMyadmin into your system

This is a built in web server that is automatically configured when you install it.

Go through below links

For windows

http://www.wampserver.com/en/index.php

and

http://www.apachefriends.org/en/xampp-windows.html

XAMPP for linux also

http://www.apachefriends.org/en/xampp-linux.html

and for other OS

http://www.apachefriends.org/en/xampp.html

Thursday, August 16, 2007

Some Nice Site for PHP,MySql,Ajax etc for Beginners

Php,MySql, Ajax,XML,JavaScript, etc

http://www.w3schools.com/

http://www.tizag.com/

For PHP


http://php.net/

For pear

http://pear.php.net/


For Smarty

http://smarty.php.net/

Image to Flash convert code using PHP

convery.php

require("class.imageconverter.php");

$img = new ImageConverter("image.jpg","swf");

?>

class.imageconverter.php


class ImageConverter {

var $imtype;
var $im;
var $imname;
var $imconvertedtype;
var $output;

function imageConverter() {

/* parse arguments */
$numargs = func_num_args();
$imagefile = func_get_arg(0);
$convertedtype = func_get_arg(1);
$output = 0;
if($numargs > 2) $this->output = func_get_arg(2);

/* ask the type of original file */
$fileinfo = pathinfo($imagefile);
$imtype = $fileinfo["extension"];
$this->imname = basename($fileinfo["basename"],".".$imtype);
$this->imtype = $imtype;

/* create the image variable of original file */
switch ($imtype) {
case "gif":
$this->im = imageCreateFromGIF($imagefile);
break;
case "jpg":
$this->im = imageCreateFromJPEG($imagefile);
break;
case "png":
$this->im = imageCreateFromPNG($imagefile);
break;
case "wbmp":
$this->im = imageCreateFromWBMP($imagefile);
break;
/*
mail me if you have/find this functionality bellow */
/*
case "swf":
$this->im = $this->imageCreateFromSWF($imagefile);
break;
*/
}

/* convert to intended type */
$this->convertImage($convertedtype);
}

function convertImage($type) {

/* check the converted image type availability,
if it is not available, it will be casted to jpeg :) */
$validtype = $this->validateType($type);


if($this->output) {

/* show the image */
switch($validtype){
case 'jpeg' :
case 'jpg' :
header("Content-type: image/jpeg");
if($this->imtype == 'gif' or $this->imtype == 'png') {
$image = $this->replaceTransparentWhite($this->im);
imageJPEG($image);
} else
imageJPEG($this->im);
break;
case 'gif' :
header("Content-type: image/gif");
imageGIF($this->im);
break;
case 'png' :
header("Content-type: image/png");
imagePNG($this->im);
break;
case 'wbmp' :
header("Content-type: image/vnd.wap.wbmp");
imageWBMP($this->im);
break;
case 'swf' :
header("Content-type: application/x-shockwave-flash");
$this->imageSWF($this->im);
break;
}

} else {
/* save the image */
switch($validtype){
case 'jpeg' :
case 'jpg' :
if($this->imtype == 'gif' or $this->imtype == 'png') {
/* replace transparent with white */
$image = $this->replaceTransparentWhite($this->im);
imageJPEG($image,$this->imname.".jpg");
} else
imageJPEG($this->im,$this->imname.".jpg");
break;
case 'gif' :
imageGIF($this->im,$this->imname.".gif");
break;
case 'png' :
imagePNG($this->im,$this->imname.".png");
break;
case 'wbmp' :
imageWBMP($this->im,$this->imname.".wbmp");
break;
case 'swf' :
$this->imageSWF($this->im,$this->imname.".swf");
break;

}

}
}

/* convert image to SWF */
function imageSWF() {

/* parse arguments */
$numargs = func_num_args();
$image = func_get_arg(0);
$swfname = "";
if($numargs > 1) $swfname = func_get_arg(1);

/* image must be in jpeg and
convert jpeg to SWFBitmap
can be done by buffering it */
ob_start();
imagejpeg($image);
$buffimg = ob_get_contents();
ob_end_clean();

$img = new SWFBitmap($buffimg);

$w = $img->getWidth();
$h = $img->getHeight();

$movie = new SWFMovie();
$movie->setDimension($w, $h);
$movie->add($img);

if($swfname)
$movie->save($swfname);
else
$movie->output;

}


/* convert SWF to image */
function imageCreateFromSWF($swffile) {

die("No SWF converter in this library");

}

function validateType($type) {
/* check image type availability*/
$is_available = FALSE;

switch($type){
case 'jpeg' :
case 'jpg' :
if(function_exists("imagejpeg"))
$is_available = TRUE;
break;
case 'gif' :
if(function_exists("imagegif"))
$is_available = TRUE;
break;
case 'png' :
if(function_exists("imagepng"))
$is_available = TRUE;
break;
case 'wbmp' :
if(function_exists("imagewbmp"))
$is_available = TRUE;
break;
case 'swf' :
if(class_exists("swfmovie"))
$is_available = TRUE;
break;
}
if(!$is_available && function_exists("imagejpeg")){
/* if not available, cast image type to jpeg*/
return "jpeg";
}
else if(!$is_available && !function_exists("imagejpeg")){
die("No image support in this PHP server");
}
else
return $type;
}

function replaceTransparentWhite($im){
$src_w = ImageSX($im);
$src_h = ImageSY($im);
$backgroundimage = imagecreatetruecolor($src_w, $src_h);
$white = ImageColorAllocate ($backgroundimage, 255, 255, 255);
ImageFill($backgroundimage,0,0,$white);
ImageAlphaBlending($backgroundimage, TRUE);
imagecopy($backgroundimage, $im, 0,0,0,0, $src_w, $src_h);
return $backgroundimage;
}
}
?>

Currency Converter Using PHP

below function used to convert one currency to another

function get_conversion($cur_from,$cur_to){
if(strlen($cur_from)==0){
$cur_from = "USD";
}
if(strlen($cur_to)==0){
$cur_from = "PHP";
}
$host="finance.yahoo.com";
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
{
$errorstr="$errstr ($errno)
\n";
return false;
}
else
{
$file="/d/quotes.csv";
$str = "?s=".$cur_from.$cur_to."=X&f=sl1d1t1ba&e=.csv";
$out = "GET ".$file.$str." HTTP/1.0\r\n";
$out .= "Host: www.yahoo.com\r\n";
$out .= "Connection: Close\r\n\r\n";
@fputs($fp, $out);
while (!@feof($fp))
{
$data .= @fgets($fp, 128);
}
@fclose($fp);
@preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match);
$data =$match[2];
$search = array ("']*?>.*?'si","'<[\/\!]*?[^<>]*?>'si","'([\r\n])[\s]+'","'&(quot|#34);'i","'&(amp|#38);'i","'&(lt|#60);'i","'&(gt|#62);'i","'&(nbsp|#160);'i","'&(iexcl|#161);'i","'&(cent|#162);'i","'&(pound|#163);'i","'&(copy|#169);'i","'&#(\d+);'e");
$replace = array ("","","\\1","\"","&","<",">"," ",chr(161),chr(162),chr(163),chr(169),"chr(\\1)");
$data = @preg_replace($search, $replace, $data);
$result = split(",",$data);
return $result[1];
}//else
}//end get_conversion

$value =2;
$x = get_conversion('USD','EUR');
$x = $x * $value;


echo "Conversion Result : ".$x."";
?>

$value means 1,2 etc that means 1 USD = -- EUR
etc

below are the currency names

Installing Apache PHP and MySQL

PHP and MySQL are usually associated with LAMP (Linux, Apache, MySQL, PHP). However, most PHP developer ( including me ) are actually using Windows when developing the PHP application. So this page will only cover the WAMP ( Windows, Apache, MySQL, PHP ). You will learn how to install Apache, PHP, and MySQL under Windows platform.

The first step is to download the packages :

You should get the latest version of each packages. As for the example in this tutorial i'm using Apache 2.0.50 ( apache_2.0.50-win32-x86-no_ssl.msi ), PHP 4.3.10 ( php-4.3.10-Win32.zip ) and MySQL 4.0.18 ( mysql-4.0.18-win.zip ).

Now let's start the installation process one by one.

Go through below links for more details : -

http://www.php-mysql-tutorial.com/install-apache-php-mysql.php

Enable curl with XAMPP on Windows XP

To enable curl library with XAMPP we need to modify the php.ini files in our xampp folder.

1) Locate the following files:
C:\Program Files\xampp\apache\bin\php.ini
C:\Program Files\xampp\php\php.ini
C:\Program Files\xampp\php\php4\php.ini

2) Uncomment the following line on your php.ini file by removing the semicolon.

;extension=php_curl.dll

3) Restart your apache server.

4) Check your phpinfo if curl was properly enabled.