24 Mei 2009

0 komentar
PHP Functions

A function is something that performs a specific task. People write functions if they plan on doing the same task over and over again. This allows you to only write the code once and save a lot of time and space.

Although in the next few pages we will lean how to write our own functions, PHP has several functions that already exist for us to use. Although they all have different uses, all functions are phrased as: name(argument). The name being the name of the function, and the argument being the value(s) it is using.

Here are some examples of functions already in PHP:

$a = abs(-.43);
$b = sqrt(16);
$c = round(12.3);
print "The absolute value of -.43 is " . $a . "
";
print "The square root of 16 is " . $b . "
";
print "12.3 rounded is " . $c . " and 12.5 rounded is " . round(12.5);
?>

This gives an example of three functions; absolute value, square root, and rounding. As you can see you can use the function right in the print statement or you can assign it to a variable. A list of functions can PHP has the ability to dynamically generate the time and date. Using a simple line of code we are able to include this on our site, however it is important to know how the formatting works.



The above code outputs a long string of numbers. What these numbers represent is the time based in the amount of seconds that have passed since January 1 1970 00:00:00 GMT. This number can also be assigned to a variable:

$b = time ();
print $b;
?>

Although this is a handy feature, sometimes you want a more formatted and human friendly representation of the date. You can use the date function in conjunction with the time function to display this in the format of date ( format , time ) In our case we want the start time to be now, so we will call the time first. We will demonstrate many different types of formatting

$b = time ();
print date("m/d/y",$b) . "
";
print date("D, F jS",$b) . "
";
print date("l, F jS Y",$b) . "
";
print date("g:i A",$b) . "
";
print date("r",$b) . "
";
print date("g:i:s A D, F jS Y",$b) . "
";
?>

When you run this code you will see that the information is formatted in many different ways. What each of the letters means for formatting is explained on the next page.

Date Function Formatting

As you can see in our last example there are tons of different formats that can be used in the date feature. Below is a summary of the variable used in date, and what each does. Remember they ARE CaSe sEnsItIVe:

DAYS
d - day of the month 2 digits (01-31)
j - day of the month (1-31)
D - 3 letter day (Mon - Sun)
l - full name of day (Monday - Sunday)
N - 1=Monday, 2=Tuesday, etc (1-7)
S - suffix for date (st, nd, rd)
w - 0=Sunday, 1=Monday (0-6)
z - day of the year (1=365)

WEEK
W - week of the year (1-52)

MONTH
F - Full name of month (January - December)
m - 2 digit month number (01-12)
n - month number (1-12)
M - 3 letter month (Jan - Dec)
t - Days in the month (28-31)

YEAR
L - leap year (0 no, 1 yes)
o - ISO-8601 year number (Ex. 1979, 2006)
Y - four digit year (Ex. 1979, 2006)
y - two digit year (Ex. 79, 06)

TIME
a - am or pm
A - AM or PM
B - Swatch Internet time (000 - 999)
g - 12 hour (1-12)
G - 24 hour c (0-23)
h - 2 digit 12 hour (01-12)
H - 2 digit 24 hour (00-23)
i - 2 digit minutes (00-59)
s 0 2 digit seconds (00-59)

OTHER e - timezone (Ex: GMT, CST)
I - daylight savings (1=yes, 0=no)
O - offset GMT (Ex: 0200)
Z - offset in seconds (-43200 - 43200)
r - full RFC 2822 formatted date

Writing Functions
While having pre-made functions is useful, for most things you are going to want the flexibility to write your own custom functions. A function you create takes this shape: function functionname () { your code }

Below is an example of two simple functions:

function examplefunction ()
{
print "Hi, I'm a Function
";
}
function sqr( $num )
{
$NumSqr = $num * $num;
return $NumSqr;
}
Print "Sample Line 1
";
examplefunction();
Print "Sample Line 3
";
$a = 9;
$b = sqr( $a );
Print $a . "^2 = " . $b;
?>

As you can see above, the code we defined between the { and } is all executed when we call the function below. In our first example (examplefunction) we used the function to simply print text. In our second function (sqr) we needed an operand to complete the math within the function. We put this inside the parenthesis () after the function name. We then add in the RETURN line, so that the value is outputted to the spot in the code where we originally called the function.

Functions can contain any of the information we have learned so far. Let's combine functions with some of the material we learned earlier to create a multiplication table:

function mul()
{
global $start;
print "";
for ($num=1; $num <= 10; $num++ )
{
$cell = $num * $start;
print " " . $cell . " ";
}
print "";
}
$start = 0;
print "";
while ( $start <=10 )
{
mul();
$start++;
}
print "
";
?>

One new thing you may have noticed is "GLOBAL". Since the variable $start is not defined within the function, we use the tag "GLOBAL" to let it know that it needs to use the $start variable that we have defined outside of the function.
0 komentar

How to Install and Configure PHP 5 to Run with Apache on Windows

by Christopher Heng, thesitewizard.com

Many web developers want to run Apache and PHP on their own computer since it allows them to easily test their scripts and programs before they put them "live" on the Internet. This article gives a step by step guide on how you can install and configure PHP5 to work together with the Apache HTTP Server on Windows. The procedure has been tested to work on both Windows XP and Vista.

If you have not already installed Apache on your machine, check out one of the guides listed below. This "How To" guide assumes that you have already completed installing Apache.

Note: those planning to install PHP 4 on Apache 1.x should read my article How to Install and Configure PHP4 to Run with Apache on Windows instead.

Steps to Setting Up PHP 5

  1. Download PHP 5

    Before you begin, get a copy of PHP 5 from the PHP download page. In particular, download the zip package from the "Windows Binaries" section - that is, don't get the installer. For example, select the package labelled "PHP 5.2.5 zip package" if 5.2.5 is the current version.

  2. Install PHP 5

    Create a folder on your hard disk for PHP. I suggest "c:\php" although you can use other names if you wish. Personally though, I prefer to avoid names with spaces in it, like "c:\Program Files\php" to avoid potential problems with programs that cannot handle such things. I will assume that you used c:\php in this tutorial.

    Extract all the files from the zip package into that folder. To do that simply double-click the zip file to open it, and drag all the files and folders to c:\php.

  3. Upgraders: Remove the Old PHP.INI File from Your Windows Directory

    If you are upgrading to PHP 5 from an older version, go to your windows directory, typically c:\windows, and delete any php.ini file that you have previously placed there.

  4. Configuring PHP

    Go to the c:\php folder and make a copy of the file "php.ini-recommended". Name the new file "php.ini". That is, you should now have a file "c:\php\php.ini", identical in contents with "c:\php\php.ini-recommended".

    Note: if you are using Apache 1, you should either move the php.ini file to your windows directory, "C:\Windows" on most systems, or configure your PATH environment variable to include "c:\php". If you don't know how to do the latter, just move the php.ini file to the "c:\windows" folder. You do not have to do this if you are using Apache 2, since we will include a directive later in the Apache 2 configuration file to specify the location of the php.ini file.

    Use an ASCII text editor (such as Notepad, which can be found in the Accessories folder of your Start menu) to open "php.ini". You may need to make the following changes to the file, depending on your requirements:

    1. Enable Short Open Tags

      Search for the line that reads:

      short_open_tag = Off

      If short_open_tag is set to "off", tags like "commercial web hosts that support PHP have no issues with your scripts using "

      short_open_tag = On
    2. Magic Quotes

      By default, input data is not escaped with backslashes. That is, if your visitors enter an inverted comma (single quote) into your web form, the script will receive that unadorned inverted comma (single quote). This is for the most part desirable unless you special requirements. If you want your input data to have the backslash ("\") prefix, such as, for example, to mimic your web host's settings, search for the following:

      magic_quotes_gpc = Off

      and replace it with:

      magic_quotes_gpc = On

      Do not do this unless your web host has this setting as well. Even with the setting of "Off", you can still use the addslashes() function in PHP to add the slashes for the specific pieces of data that need them.

    3. Register Globals

      A number of older scripts assume that all data sent by a form will automatically have a PHP variable of the same name. For example, if your form has an input field with a name of "something", older PHP scripts assume that the PHP processor will automatically create a variable called $something that contains the value set in that field.

      If you are running such scripts, you will need to look for the following field:

      register_globals = Off

      and change it to the following:

      register_globals = On

      WARNING: Do NOT do this unless you have third party scripts that need it. When writing new scripts, it's best to always code with the assumption that the register_globals item is set to "Off".

    4. Display Errors

      On a "live" website, you typically want errors in your script to be silently logged to a PHP error file. On your own local machine, however, while you are testing and debugging a PHP script, it is probably more convenient to have error messages sent to the browser window when they appear. This way, you won't miss errors if you forget to check the error log file.

      If you want PHP to display error messages in your browser window, look for the following:

      display_errors = Off

      And change it to:

      display_errors = On

      This value should always be set to "Off" for a "live" website.

    5. Session Path

      If your script uses sessions, look for the following line:

      ;session.save_path = "/tmp"

      The session.save_path sets the folder where PHP saves its session files. Since "/tmp" does not exist on Windows, you will need to set it to a directory that does. One way is to create a folder called (say) "c:\tmp" (the way you created c:\php earlier), and point this setting to that folder. If you do that, change the line to the following:

      session.save_path = "c:\tmp"

      Notice that in addition to changing the path, I also removed the semi-colon (";") prefix from the line.

      Alternatively, you can find out the current TEMP folder on your computer and use that. Or create a "tmp" folder in your PHP directory, like "c:\php\tmp" and set the configuration file accordingly. The possibilities are endless. If you can't decide, just create "c:\tmp" and do as I said above.

    6. SMTP Server

      If your script uses the mail() function, and you want the function to successfully send mail on your local machine, look for the following section:

      [mail function]
      ; For Win32 only.
      SMTP = localhost
      smtp_port = 25

      ; For Win32 only.
      ;sendmail_from = me@example.com

      Change it to point to your SMTP server and email account. For example, if your SMTP server is "mail.example.com" and your email address is "youremail@example.com", change the code to:

      [mail function]
      SMTP = mail.example.com
      smtp_port = 25
      sendmail_from = youremail@example.com

      Note that after you do this, when your script tries to use the mail() function, you will need to be connected to your ISP for the function to succeed. If you do not modify the above lines and attempt to use mail() in your script, the function will return a fail code, and display (or log) the error (depending on how you configure php.ini to handle errors).

      (Note that in Apache 1.x, the smtp_port line may not be present. If so, don't include it.)

How to Configure Apache for PHP 5

There are two ways to set up Apache to use PHP: the first is to configure it to load the PHP interpreter as an Apache module. The second is to configure it to run the interpreter as a CGI binary. I will supply information for how you can accomplish both, but you should only implement one of these methods. Choose the module method if your web host also installed PHP as an Apache module, and use the CGI method if they have implemented it to run as a CGI binary.

  1. Running PHP 5 as an Apache Module

    To configure Apache to load PHP as a module to parse your PHP scripts, use an ASCII text editor to open the Apache configuration file, "httpd.conf". If you use Apache 1.x, the file is found in "c:\Program Files\Apache Group\Apache\conf\". Apache 2.0.x users can find it in "C:\Program Files\Apache Group\Apache2\conf\" while Apache 2.2.x users can find it in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\". Basically, it's in the "conf" folder of wherever you installed Apache.

    Search for the section of the file that has a series of "LoadModule" statements. Statements prefixed by the hash "#" sign are regarded as having been commented out.

    If you are using Apache 1.x, add the following line after all the LoadModule statements:

    LoadModule php5_module "c:/php/php5apache.dll"

    If you are using Apache 2.0.x, add the following line after all the LoadModule statements:

    LoadModule php5_module "c:/php/php5apache2.dll"

    If you are using Apache 2.2.x, add the following line instead:

    LoadModule php5_module "c:/php/php5apache2_2.dll"

    Note carefully the use of the forward slash character ("/") instead of the traditional Windows backslash ("\"). This is not a typographical error.

    If you are using Apache 1.x, search for the series of "AddModule" statements, and add the following line after all of them. You do not have to do this in any of the Apache 2 series of web servers.

    AddModule mod_php5.c

    Next, search for "AddType" in the file, and add the following line after the last "AddType" statement. Do this no matter which version of Apache you are using. For Apache 2.2.x, you can find the "AddType" lines in the section. Add the line just before the closing for that section.

    AddType application/x-httpd-php .php

    If you need to support other file types, like ".phtml", simply add them to the list, like this:

    AddType application/x-httpd-php .phtml

    Finally, for those using one of the Apache 2 versions, you will need to indicate the location of your PHP ini file. Add the following line to the end of your httpd.conf file.

    PHPIniDir "c:/php"

    Of course if you used a different directory for your PHP installation, you will need to change "c:/php" to that path. Remember to use the forward slash ("/") here again.

    If you are using Apache 1, you will have already placed your php.ini file in either the Windows directory or somewhere in your PATH, so PHP should be able to find it by itself. You can of course do the same if you are using Apache 2, but I find modifying the Apache configuration file a better solution than cluttering your c:\windows directory or your PATH variable.

  2. Running PHP 5 as a CGI Binary

    If you have configured PHP 5 to run as an Apache module, skip forward to the next section. This section is for those who want to configure PHP to run as a CGI binary.

    The procedure is the same whether you are using the Apache 1.x series or one of the 2.x series.

    Search for the portion of your Apache configuration file which has the ScriptAlias section. Add the line from the box below immediately after the ScriptAlias line for "cgi-bin". If you use Apache 2.2.x, make sure that the line goes before the closing for that section.

    Note that if you installed PHP elsewhere, such as "c:\Program Files\php\", you should substitute the appropriate path in place of "c:/php/" (for example, "c:/Program Files/php/"). Observe carefully that I used forward slashes ("/") instead of the usual Windows backslashes ("\") below. You will need to do the same.

    ScriptAlias /php/ "c:/php/"

    Apache needs to be configured for the PHP MIME type. Search for the "AddType" comment block explaining its use, and add the AddType line in the box below after it. For Apache 2.2.x, you can find the AddType lines in the section. Add the following line just before the closing for that section.

    AddType application/x-httpd-php .php

    As in the case of running PHP as an Apache module, you can add whatever extensions you want Apache to recognise as PHP scripts, such as:

    AddType application/x-httpd-php .phtml

    Next, you will need to tell the server to execute the PHP executable each time it encounters a PHP script. Add the following somewhere in the file, such as after the comment block explaining "Action". If you use Apache 2.2.x, you can simply add it immediately after your "AddType" statement above; there's no "Action" comment block in Apache 2.2.x.

    Action application/x-httpd-php "/php/php-cgi.exe"

    Note: the "/php/" portion will be recognised as a ScriptAlias, a sort of macro which will be expanded to "c:/php/" (or "c:/Program Files/php/" if you installed PHP there) by Apache. In other words, don't put "c:/php/php.exe" or "c:/Program Files/php/php.exe" in that directive, put "/php/php-cgi.exe".

    If you are using Apache 2.2.x, look for the following section in the httpd.conf file:


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

    Add the following lines immediately after the section you just found.


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
  3. Configuring the Default Index Page

    This section applies to all users, whether you are using PHP as a module or as a CGI binary.

    If you create a file index.php, and want Apache to load it as the directory index page for your website, you will have to add another line to the "httpd.conf" file. To do this, look for the line in the file that begins with "DirectoryIndex" and add "index.php" to the list of files on that line. For example, if the line used to be:

    DirectoryIndex index.html

    change it to:

    DirectoryIndex index.php index.html

    The next time you access your web server with just a directory name, like "localhost" or "localhost/directory/", Apache will send whatever your index.php script outputs, or if index.php is not available, the contents of index.html.

Restart the Apache Web Server

Restart your Apache server. This is needed because Apache needs to read the new configuration directives for PHP that you have placed into the httpd.conf file. The Apache 2.2 server can be restarted by doubleclicking the Apache Service Monitor system tray icon, and when the window appears, clicking the "Restart" button.

Testing Your PHP Installation

Create a PHP file with the following line:

Save the file as "test.php" or any other name that you fancy, but with the ".php" extension, into your Apache htdocs directory. If you are using Notepad, remember to save as "test.php" with the quotes, or the software will add a ".txt" extension behind your back.

Open your browser and access the file by typing "localhost/test.php" into your browser's address bar. Do not open the file directly on the hard disk - you'll only see the words you typed in earlier. You need to use the above URL so that the browser will try to access your Apache web server, which in turn runs PHP to interpret your script.

If all goes well, you should see a pageful of information about your PHP setup. Congratulations - you have successfully installed PHP and configured Apache to work with it. You can upload this same file, test.php, to your web host and run it there to see how your web host has set up his PHP, so that you can mimic it on your own machine.

If for some reason it does not work, check to see whether your PHP setup or your Apache setup is causing the problem. To do this, open a Command Prompt window (found in the "Accessories" folder of your "Start" menu) and run php-cgi.exe on test.php with a command line like "c:\php\php-cgi test.php" (without the quotes).

If invoking PHP from the command line causes a large HTML file with all the PHP configuration information to be displayed, then your PHP set up is fine. The problem probably lies with your Apache configuration. Make sure that you have restarted the Apache server after making configuration changes. Verify that you have configured Apache correctly by looking over, again, the instructions on this page and the steps given in How to Install and Configure Apache 1.x for Windows (for Apache 1.x users) or How to Install and Configure Apache 2 on Windows (for Apache 2.x users).

Learning PHP

The complete PHP reference manual can be obtained from the php website. You can refer to it online or download the entire set of HTML files for reference offline. As its name implies, it is a reference manual only. For tutorials, check out the PHP tutorials at thesitewizard.com. If you are new to writing PHP scripts, the following chapters may interest you:

5 Mei 2009

0 komentar

Kebutuhan Hardware Windows 7

Minimum dan perbedaan setelah dikeluarkan versi Release Candidate.

Windows 7 dipastikan akan direlease tahun ini. Tetapi seberapa besar minimum hardware yang dibutuhkan.
Untuk beta Tester yang baru direlease dibutuhkan spesifikasi seperti dibawah ini.
  • 1 GHz 32-bit atau 64-bit processor
  • 1 GB system memory
  • 16 GB harddisk space
  • VGAr DirectX 9 dengan 128MB untuk euro.
Versi Release Candidate atau yang akan direlease :
  • 1 GHz min 32-bit (x86) / 64-bit (x64) processor
  • 1 GB RAM (32-bit)/2 GB RAM (64-bit)
  • 16 GB space harddisk bagi 2 model OS 32-bit)/20 GB (64-bit)
  • DirectX 9 Windows Display Driver Model 1.0 atau lebih tinggi.
Perbedaan antara Beta dan RC, hanya berbeda pada OS 64 atau 32 bit, dimana 64 bit memiliki kebutuhan hardware lebih besar.
Disisi lain Windows 7 memiliki fitur XP mode running, sehingga OS baru dapat menjalankan program Windows XP secara mulus. Disini dibutuhkan 2 GB memory bila ingin mengaktifkan mode XP di OS Windows 7. Kedua dibutuhkan hardware dengan teknologi Virtualization.

Bila dibandingkan Vista, Windows 7 memang membutuhkan hardware lebih besar. Dibawah ini adalah kebutuhan hardware minimum ketika Windows Vista direlease
  • 1 GHz processor (32- or 64-bit)
  • 512 MB RAM ( Home Basic); 1 GB RAM untuk versi lebih tinggi
  • 15 GB space harddisk
  • DirectX 9 graphics dan 32 MB of graphics memory (untuk Home Basic); 128 MB graphics memory plus WDDM untuk versi lebih tinggi.


0 komentar
Hampir sebagian besar media mengulas procesor AMD terbaru. Performa menempel ketat Quad Core Intel

Intel boleh berbangga mengeluarkan Core i7. AMD tetap mempertahankan procesor AMD Phenom II X4 940 & 920 dengan harga lebih terjangkau. Konon untuk Phenom II X4 mampu dioverclock sampai 4Ghz. Performa Phenom II belum mmapu mengejar Core i7. Tetapi untuk aplikasi sangat ketat bersaing dengan Core Quad.
Sayang dari artikel Anandtech, kemampuan aplikasi 3D Game memang tidak berbeda banyak dengan Core 2 Duo.

Processor AMD Phenom II AMD Phenom Intel Core i7 Intel Core 2 Quad Q8xxx/Q9xxx
Manufacturing Process 45nm 65nm 45nm 45nm
L1 Cache 64K + 64K per core 64K + 64K per core 32KB + 32KB per core 32KB + 32KB per core
L2 Cache 512KB per core 512KB per core 256KB per core 2x3MB, 2x4MB or 2x6MB
L3 Cache 6MB 2MB 8MB -
Transistor Count 758M 450M 731M 456M (6MB/8MB L2) or 820M (12MB L2)
Die Size 258 mm2 285 mm2 263 mm2 164 mm2 (6MB/8MB L2) or 214 mm2 (12MB L2)


Spesifikasi Phenom II
Processor Clock Speed Uncore Clock L2 Cache L3 Cache TDP Price
AMD Phenom II X4 940 3.0GHz 1.8GHz 2MB 6MB 125W $275
AMD Phenom II X4 920 2.8GHz 1.8GHz 2MB 6MB 125W $235
AMD Phenom 9950 2.6GHz 2.0GHz 2MB 2MB 140W $174

Berikut media yang telah mencoba kemampuan Phenom II

AMD vs Intel

0 komentar

AMD Tantang Intel Dengan Phenom II

Persaingan dalam bisnis komputer semakin menjadi setelah AMD (Advanced Micro Devices) mengumumkan akan mencoba mengalahkan Intel yang masih memegang persaingan untuk mikroprosesor.


Bahkan untuk lebih memanaskan persaingan perang harga di antara keduanya, AMD menghadirkan prosesor model baru dalam jajaran prosesor Phenom II-nya.

Prosesor Phenom II 'Dragon' ini menggunakan teknologi 45 nm dan terdiri atas prosesor quad-core (X4) dan triple-core (X3).

Harga dari prosesor triple-core Phenom II X3 720 Black Edition adalah US$145, bersaing dengan prosesor besutan Intel, Core 2 Duo (dual-core) E8400 yang dibandrol pada harga US$163.

Sementara itu, prosesor quad-core X4 810 (2.6GHz) dibanderol pada harga US$175 dan akan head to head dengan prosesor Intel Core 2 Quad Q8200 yang dipatok pada harga US$163.

Dikutip dari Cnet, Selasa (10/2/2009), prosesor Phenom II kompatibel dengan socket AM2+ atau AM3 dan mendukung DDR2 atau teknologi memori DDR3.

Model-model yang akan menghiasi jajaran prosesor Phenom II seperti:

1. AMD Phenom II X4 910 - (2.6GHz)
2. AMD Phenom II X4 810 - (2.6GHz)
3. AMD Phenom II X4 805 - (2.5GHz)
4. AMD Phenom II X3 720 Black Edition - (2.8GHz)
5. AMD Phenom II X3 710 - (2.6GHz)
 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com Distributed by Blogger Blog Templates