simple explode program in php

<?php
//explode string into array
$str=" Test Explode function in php ";
print_r (explode(" ",$str));

?>

it will be Output like:

Array ( [0] => [1] => Test [2] => Explode [3] => function [4] => in [5] => php [6] => )

simple example php function

<?php
//simple example php function
function welcome()
{
echo "Welcome to Function";
}
welcome();
?>

how can create notepad file in php

<?php
//how can create notepad file in php
$t= fopen("testfiles.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($t, $txt);
$txt = "Jane Doe\n";
fwrite($t, $txt);
fclose($t);

?>

simple uploading script in php

<?php
//simple uploading script in php
//echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "File Name ".$_FILES["file"]["name"] . "<br>";
echo "File Type ".$_FILES["file"]["type"] . "<br>";
echo "File Temp ".$_FILES["file"]["tmp_name"] . "<br>";
echo "File Size ".$_FILES["file"]["size"]."<br>";
move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);
?>
<html>
<title>Simple file uploading in php</title>
<body>
<form method="post" action="fileuploading.php" enctype="multipart/form-data" >
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

While loop example in php

<?php
//While loop example in php(print 1 to 10)
$x=1;
while($x<=10)
{
echo $x;
$x++;
}
?>

switch case example in php

<?php
//switch case example in php
$day="Sunday";
switch($day)
{
  case "Monday":
   echo "Monday";
  break;
  case "Tuesday":
   echo "Tuesday";
  break;
  case "Wednesday":
   echo "Wednesday";
  break;
  case "Thurday":
   echo "Thurday";
  break;
  case "Friday":
   echo "Friday";
  break;
  case "Saturday":
   echo "Saturday";
  break;
  default:
  echo "Sunday";
}
?>

what is differences between PHP4 and PHP5

PHP4 and PHP5:
  • PHP5 removed register_globals, magic quotes, and safe mode. This was due to the fact that register_globals had opened security holes by intentionally allowing runtime data injection and the use of magic quotes had an unpredictable nature.
  • PHP4 was powered by Zend Engine 1.0, while PHP5 was powered by Zend Engine II.
  • PHP5 replaced magic quotes with the addslashes() function in order to escape characters.
  • PHP4 is more of a procedure language while PHP5 is object oriented.
  • In PHP5 one can declare a class as Abstract.
  • PHP5 incorporates static methods and properties.
  • PHP5 introduces a special function called __autoload()
  • PHP5 allows one to declare a class or method as Final
  • PHP5 introduces a number of magic methods, such as __call, __get, __set and __toString
  • In PHP5, there are 3 levels of visibilities: Public, private and protected.
  • PHP5 introduced exceptions.
  • In PHP4, everything was passed by value, including objects. Whereas in PHP5, all objects are passed by reference.
  • PHP5 introduces interfaces. All the methods defined in an interface must be public.
  • PHP5 introduces new error level defined as ‘E_STRICT’
  • PHP5 introduces new default extensions such as SimpleXML, DOM and XSL, PDO, and Hash.
  • PHP5 introduces new functions.
  • PHP5 introduces some new reserved keywords.
  • PHP5 includes additional OOP concepts than php4, like access specifiers , inheritance etc.
  • PHP5 includes improved support of current content management systems.
  • PHP5 includes reduced consumption of RAM.
  • PHP5 introduces increased security against exploitation of vulnerabilities in PHP scripts.
  • PHP5 introduces easier programming through new functions and extensions.
  • PHP5 introduces a new MySQL extension named MySQLi for developers using MySQL 4.1 and later.
  • In PHP5, SQLite has been bundled with PHP.
  • PHP5 introduces a brand new built-in SOAP extension for interoperability with Web Services.
  • PHP5 introduces a new SimpleXML extension for easily accessing and manipulating XML as PHP objects. It can also interface with the DOM extension and vice-versa.
  • In PHP5, streams have been greatly improved, including the ability to access low-level socket operations on streams.

What is the difference between echo and print statement in PHP

What is the difference between echo and print statement in PHP?

Multiple expressions can be given in echo statement, where as print cannot take multiple expressions. 
Echo does not have a return value, where as print returns a value indicating successful execution. 
Echo is faster when compared with print.

Create table in mysql

<?php
create table user(id int(10) NOT NULL AUTO_INCREMENT,username varchar(100) not null,password varchar(100),primary key(id));
?>

mysql db connection script php

<?php

//Mysql connection
$con=mysql_connect("localhost","root","");

if (mysqli_connect_errno()) {
  echo " Failed to connect to MySQL: " . mysqli_connect_error();
}

//Select particular db
mysql_select_db("test",$con);
?>

Ternary operator example in php

The Ternary operator is like if-else statement, Ternary operator is made for two different actions, one if the condition is true, the other one if it's false but with nested Ternary operators we can use it like an if-elseif.

Syntax

(condition) ? TRUE : FALSE

<?php
$i=0;
echo $output=($i==0)? "TRUE" : "FALSE";
?>

php heredoc simple example

<?php
$a=" Test Php Heredoc Syntax ";

print <<< EOD
{$a}
EOD;
?>