Php Tips

You can write less code for same result and It is more understandable.


$var = $var + 1; // Add 1 to $var
$var ++; // Gives same result


Also work with this;

$var = $var - 1; // Sub 1 to $var
$var --; // Gives same result



$var = "It"
$var = $var + " can be..."; // Result : It can be...
$var .= " can be..."; // Result : It can be...


Shortcut for If Else;

if($var != "page"){
$out ++; // Add 1 to $out
}

if($var != "page") $out ++; // Gives same result (Add 1 to $out)


Much more is coming soon. (:

Woltlab Burning Board 2.3.3 Color Palette Fix for Opera

There is a bug or lack or anything but user can not set color with color palette. Here is fix for this issue If you are using wBB 2.3.x

1- Open your acp/templates/designpack_colorchooser.htm file with your text editor

2- Find this block;

x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);

3- Replace with this code;
e=window.event;      // added
e.layerX=e.offsetX; // added
e.layerY=e.offsetY; // added

x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);


4- Do the same things for Cache/templates/acp/designpack_colorchooser.htm file
-------------------------------------------------------------------------------------

Woltlab Burning Board 2.3.3 admin panelinde kullanılan Renk paleti Opera ile düzgün çalışması için yapılmış küçük bir güncelleme.

1- acp/templates/designpack_colorchooser.htm dosyasını Text editörü ile açın

2- Bu kod satırını bulun;
x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);

3- Bu kod ile değiştirin;
e=window.event;      // eklendi
e.layerX=e.offsetX; // eklendi
e.layerY=e.offsetY; // eklendi

x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);


4- Aynı şeyi Cache/templates/acp/designpack_colorchooser.htm dosyası içinde yapın. Artık renk paletini Opera tarayıcısı ile birlikte rahatlıkla kullanabilirsiniz.

While Loop in Php

While loop saves your time. If you want to print all mysql rows, all value in array, you can use While loop.

Simple Example;


$i = 0;
while ( $i <= 10 ) {
echo "Number: " . $i;
$i++;
}


First; we defined $i as '0'. After we started the While loop statement. If $i number is less or equal to '10', process will continue. If $i number equals to '10', process will end and PHP will continue to generate page.

Here is other syntax.

$i = 1;
while ($i <= 10):
echo $i;
$i++;
endwhile;


While, Foreach, For Next loop statement are save your time to listing any mysql result.

Auto Resize image With PHP

Most of time, It makes me angry. Open image, resize and then upload again. If you believe you fixed the size issue, but after updating web site, you can see, product image is overflow. Download all image again, and resize it to true size and upload it again.

Then I wrote this function for along time ago. It is loading image and resizing what you want with picture quality. So, you can reduce image size and you can fix your image overflow issue.

Here is PHP function code;

<?php
/**
*
@author PCoder
*
@copyright 2009
* Auto Resized Image / Thumb
*/
function resize($dosya, $yukseklik, $genislik, $kalite)
{
$boyut = GetImageSize($dosya);
/* Get image Width and Height */
$resim_genis = $boyut[0];
/* Real image width */
$resim_yuksek = $boyut[1];
/* Real image height */
if ($resim_genis > $resim_yuksek) {
/* If width is bigger than height */
$yeni_y = ceil(($genislik * $resim_yuksek) / $resim_genis);
$yeni_x = $yukseklik;
}
else {
/* If height is bigger than width */
$yeni_y = ceil(($yukseklik * $resim_genis) / $resim_yuksek);
$yeni_x = $genislik;
}
$image_p = imagecreatetruecolor($yeni_x, $yeni_y);
/* Create image with new size */
$image = imagecreatefromjpeg($dosya);
/* Load file from server that defined */
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $yeni_x, $yeni_y, $resim_genis,
$resim_yuksek);
/* Entegret the new sized image with loaded file */
imagejpeg($image_p, null, $kalite);
/* Create JPG file */
Header("Content-type: image/jpeg");
/* Some browser don't display image, this header() function fix it */
}
?>


Just use this function with your var;
<?php
resize("logo.jpg",150,150,90);
?>

What is PHP?

PHP is a popular programming language for extending web pages with dynamic features. It is using small and big company, big project or very small project. It has wide-range usability. Youtube, Facebook and Joomla is written with PHP.

Php is powerfull and free. So, Everyone can use it for commercial. You can run your PHP script most of OS. Mac, Windows or Unix. You must just configure your server for PHP.

Php can be use with MySQL, MSSQL or other database. You can create your own dynamic web site in short time.

Here is simple PHP example;

<?php
/**
*
@author PCoder
*
@copyright 2009
* Php Hello World
*/

echo("Hello World "); /* Result: Hello World */
Print("Hello World "); /* Result: Hello World */

/* Define a var for Hello World */

$var = "Hello World ";
echo $var; /* You can use this : echo($var); */
print $var; /* You can use this : print($var); */
?>