Arrays can be passed from a html web form to a php script. The ‘name’ attribute of the input type should be specified as an array.
example :
<form method="post" action="arrayformdata.php">
<label>Tags</label>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="submit" value="submit">
</form>
</html>
To receive the array in a php script, we use the $_POST as
<pre lang="php">
<?php
$postedtags = $_POST['tags'];
foreach ($postedtags as $tag){
echo "<br />$tag";
}
?>
The localtime function is used to get the current date and time from the operating system as a C style associative array or list.
Syntax:
array localtime ()
array localtime (integer $Time)
array localtime (integer $Time, boolean $Associative)
Read more…
The php function rmdir() enables developers to remove a directory from the file system. The process trying to delete the directory must have enough permissions and the directory must be empty. The rmdir() function requires a string representing the path to the directory to be deleted. It returns TRUE on success or FALSE on failure.
Example code:
<?php
if (!is_dir('exampledir')) {
mkdir('exampledir');
}
rmdir('exampledir');
?>
Why Windows code does not working in Linux and Unix or Linux code does not working in Windows and Unix.
This is the most frequently asked question in PHP. While running a PHP document in Windows we get the form variable by either GET or POST method. For which we use the following code:
$name=$_POST["txtName"]; or $name=$_GET["txtName"];
While using the same code in Linux and Unix you will get a error message. To solve this problem or to run a PHP page in a different operating system without any errors, first declare the GET variables and POST variables globally using the following code. Read more…
If you have ever wondered how to include another PHP file into a PHP script, this simple one line code sample will show you how.
<?php
// Place this into your PHP page
// and edit the file name
include "some_other_file.php";
?>
if (isset($var)) {
echo “the var is set, and equals $var. It may be empty though.”;
}
http://www.php.net/isset
isset() will tell you is a varaible has been defined. This can bite some
users, because it will return true even if the varable has an empty
value. Look at empty() as well. Sometimes you’ll want to use one rather
than the other. Note that even “0″ and 0 are considered empty. Read more…
Put the following code at the top of your page.
<?
$URL="http://www.yourdomain.com";
header ("Location: $URL");
?>
Show IP Display visitor’s IP Address in a graphic with this simple php code.
(Please do not link to this image, it is for demonstration only.)
Your IP Address

create a new page, copy the text below and save it as image.php (or whatever you wish)
<?php
$img_number = imagecreate(275,25);
$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,255,255,255);<span id="more-1257"></span>
imagefill($img_number,0,0,$backcolor);
$number = " Your IP is $_SERVER[REMOTE_ADDR]";
Imagestring($img_number,10,5,5,$number,$textcolor);
header("Content-type: image/jpeg");
imagejpeg($img_number);
?>
All you’ll need to display on other pages is the code below.
<img src="http://yoursitehere.com/image.php" border="1" alt="" />
With each new version PHP is getting more and more object oriented. In version 5.x we get two useful classes for date and time handling. Many programmers are still using outdated methods which are available in PHP mainly for compatibility reasons, so i want to introduce you to DateTime and DateTimeZone objects.
Server default Timezone
Before i do that, first let’s start with some basics, which tend to cause a lot of troubles in the beginning. Each computer has it’s own default timezone and local time set. If you are using Microsoft Windows, then probably timezone on your local machine is already set correctly, on the other hand if you are using Linux chances are that you will have to do it manually (i had to, however i am not using typical Linux so maybe this is just me). Read more…