Feeds:
Posts
Comments

Archive for the ‘PHP’ Category

PHP XML

Expat parser and DOM parser
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load(“note.xml”);
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item)
{
print $item->nodeName . ” = ” . $item->nodeValue . “<br />”;
}
?>
simplexml
<?php
$xml = simplexml_load_file(“test.xml”);
echo $xml->getName() . “<br />”;
foreach($xml->children() as $child)
{
echo $child->getName() . “: ” . $child . “<br />”;
}
?>

Read Full Post »

PHP Database

Connecting to a mysql
mysql_connect(servername,username,password);
<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
// some code
mysql_close($con);
?>
Creating Database
<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
// Create database
if (mysql_query(“CREATE DATABASE my_db”,$con))
{
echo “Database created”;
}
else
{
echo “Error creating database: ” . mysql_error();
}
// Create table in my_db database
mysql_select_db(“my_db”, $con);
$sql = “CREATE TABLE person
(
FirstName varchar(15),
LastName varchar(15),
Age int
)”;
mysql_query($sql,$con);
mysql_close($con);
?>
Insert Data From a Form Into a [...]

Read Full Post »

Advance PHP

PHP Advance
->date(“Y/m/d”);
-> Include function gives warning and continue the execution of script
-> require through fatal error and stop execution of script
include(header.php); or require(header.php);
-> File handling
$file = fopen(“welcome.txt”, “r”);
fclose($file);
fgets($file); -> one line
fgetc($file); -> one charecter
feof($file); -> end of file
<?php
$file = fopen(“welcome.txt”, “r”) or exit(“Unable to open file!”);
//Output a line of the file until the end is [...]

Read Full Post »

Basic PHP

-> Php Code start by <?php ..?> or <?.. ?>
-> variable start with $
-> All statement end with semicolon (;)
-> Concatenate operator is dot (.)
-> printing statements start with word echo or print
-> If ()
echo ..
else
echo..
-> Array $names = array(“Peter”,”Quagmire”,”Joe”);
-> Associative array
$ages = array(“Peter”=>32, “Quagmire”=>30, “Joe”=>34);
$ages['peter']
->  foreach loop
<?php
$arr=array(“one”, “two”, “three”);
foreach ($arr as $value)
{
echo “Value: ” [...]

Read Full Post »