2014 ~ PinoySourceCode

Friday, May 23, 2014

12 things we hate about PHP

 
 Do we really hate PHP? Nah. If we did, we wouldn't be running Drupal and WordPress and other frameworks at the astronomical clip we do. Nope, true PHP hate would mean switching to Java. But familiarity breeds contempt, and let's face it, what the PHP naysayers say about one of our favorite server-side scripting tool has some merit.
What follows are 12 gripes we have built up in our years of working with the language.

Switching gears is a headache
The most important challenge in creating PHP is remembering when you're typing HTML and when you're typing PHP code. Mixing them together is a big selling point for PHP but taking advantage of it can be a pain. You look at a file, and it looks like code. But wait, where's the perfunctory tag that shifts us from writing HTML to creating server instructions? It's like you've taken two files operating on two different layers and smooshed them together. You've got to mind those tags because the whole purpose is to merge code with markup. Except when it makes everything more confused.

The markup maze
Mixing server instructions with browser markup is a mistake. Over in Java land, the teams talk about strict adherence to the MVC paradigm. The model for the data goes in one file, the layout instructions that control the view go in a second set of files, and the logic that makes up the controller goes in a third. Keeping them separate keeps everything a bit more organized. But in PHP land, the bedrock design decision is that you're supposed to mix HTML markup with controller logic for the server. You can always separate them -- and many do -- but once you start doing that, you have to start asking yourself, "Why, again, are we using PHP?"

Inconsistent and idiosyncratic nomenclature
Does anyone know when we use underscores? The method base64_encode uses an underscore, but urlencode doesn't. The name php_uname has an underscore, but phpversion doesn't. Why? Did anyone think about this? Did anyone edit the API?

Meanwhile, function strcmp is case-sensitive, but strcasecmp is not. strpos is case-sensitive, but stripos is not. Does the letter i signify case-insensitivity or does the word case? Who can remember? You better.

Sorting hell
How many sort functions does the world really need? Java has one basic sort function and a simple interface for all objects. If you want another algorithm, you can add it, but most make do with the standard function. In PHP world, there's a long list of functions for sorting things: usort, sort, uksort, array_sort. (Note that only some use an underscore.) So start studying and get that cheat sheet ready.

Open source has its limits
PHP may be open source, but the good features like caching are commercial. This is just an expression of reality. Zend needs to make some money, and it supports the entire PHP world by selling the best versions to people who need it. Complaining about this is like complaining about gravity. There are just things about earth that suck. Just don't fool yourself into thinking that it's all one big open source commune.

Broken namespaces
Do you want to create your own functions? First decide whether you're going to use PHP 5.3 or later because that's when namespaces arrived. If you don't, make sure they don't collide with a library because in the old days, everything was global. And if you're going to be running PHP 5.3 and you want to use the namespaces, get used to the backslashes, one of the uglier punctuation marks ever invented.

Type safety is broken
Way broken. PHP programmers are fond of noting that this expression is true:
(string)"false" == (int)0
Notice this isn't one of those classic examples that some PHP fanboi will argue is really a side effect of a feature. After all, JavaScript has plenty of similar examples caused by its overeager type conversion. Nope. The line says that the thing on the left is a string and the thing on the right is an integer. But somehow they're all equal. It's enough to make you believe that everyone in the world could just get along in harmony if only the PHP designers were put in charge.

Too many options, too many redundancies
There are too ways to do too many things. End of line comments can be specified with either a number sign or a double slash. Both float and double mean the same thing. Simplicity is often tossed aside because people have added their own little features along the way. It's like design by committee, but the committee never met to iron out the differences.

Weird variable naming conventions
The dollar sign prefix is confusing. Perhaps it makes sense to force all variables to begin with a dollar sign because it makes inserting them into templates a bit simpler, but shouldn't the constants also start with a dollar sign?

CPU tug-o-war
There are numerical issues with big integers on 32-bit machines. They wrap around, but the 64-bit machines don't, meaning that code will run differently on different machines. You can test it on your desktop, and it will run just fine. But when you move to the server, it could do something entirely different. Then when you try to re-create the error on your desktop, you're out of luck. The only good news is that 32-bit machines may finally disappear.

SQL injections
It's not really fair to blame PHP for one of the biggest class of security holes. People slip weird SQL strings past other languages too. It's just that PHP makes it easy to suck data from a form and send it off to MySQL. Too easy. The average newbie could make the same mistake with any language, but PHP makes it far too simple.

Too many incompatible changes
There are big differences between versions. Compatibility isn't so simple. Many languages like Java or JavaScript have sacrificed fast evolution for backward compatibility. It's not uncommon for older code to run without a problem on newer machines. But not PHP. There are big differences between the various versions, and you better hope your server has the right version installed because you'll probably only notice it when weird errors start appearing. The first thing you look for when your server goes south is whether someone upgraded PHP.



Read More

Friday, April 25, 2014

Array in PHP

Suppose we want to store 100 data item. So we need 100 different variable. So this is very typical work for programmer to manage 100 different variable.To overcome this problem we create a special type variable known as array.

array is a special type of variable that store one more values in one single variable. And each element in the array has its own index.

In PHP, there are three kind of arrays:
Numeric array - An array with a numeric index starting 0,1 etc.
Associative array - An array with a string index you can start like sun,mon,tue etc.

Multidimensional array - An array containing one or more arrays

1. we can create an array by array function.

<?php

$data=array("Sun","Mon","Tue","Wed");

?>

2. we can create each array element directly.

<?php

$data[0]="Sun";
$data[1]="Mon";
$data[2]="Tue";
$data[3]="Sun";

?>

A numeric array stores each array element with a numeric index.
In the following example the index are automatically assigned (the index starts at 0):

<?php

$data=array("Sun","Mon","Tue","Wed");

for($i=0;$i<4;$i++)
{
echo $data[$i]."  ";
}
?>
Output:

Sun  Mon  Tue  Web
Read More

PHP Loop

Loop execute some statement many times till the condition is fullfill.

There are three type or loops. these loops do same work execute statement many times.
  • While loop
  • Do While loop
  • For Loop
while loop

while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is:
===========================
while (expr)
    statement
===========================
In the while loop it first check the condition then body of the loop will be executed many times untill the condition is fullfill.

Syntax
===========================
while (condition)
 {
  Code here.
 }
===========================
Exercise 1:
===========================
<?php
$i=1;
while($i<=5)
  {
  echo "Number".$i;
  $i++;
  }

?> Output

Number 1

Number 2

Number 3

Number 4

Number 5

do while

Exercise 2:

===========================
<?php

$i=1;
do
  {
  echo "Number".$i;
  $i++;
  }while($i<=5)
?>
Output

Number 1

Number 2

Number 3

Number 4

Number 5
===========================

For loop

In For loop then statement will be excuted till the condition is fullfill.

===========================
for (initilization; condition; increment)
{
  code here...;
}

===========================
Exercise 1:

<?php

for ($i=1; $i<=5; $i++)

  {

  echo "Number".$i;

  }

?>
Output

Number 1
Number 2
Number 3
Number 4
Number 5
Read More

HTML Form tag

When creating textbox. labels,textarea , radio button etc. So this necessary to send these control value to the server.

code:

<form name="formanme" action="action.php" method="post">
your input box, textbox etc..
</form>

name  name of the form
action write page name on which page you want to send values. if you take action blank like action=""               then values send on same page.
method  there are two method post and get.
post send value to the server but values not show on URL.
get send value to the server but values show on URL.

Exercise:

<html>
<head>
<title>Exercise</title>
</head>
<body>
<form name="formanme" action="action.php" method="post">
User Name<input name="username" type="text" /><br />
</form>
</body>
</html>

save this php script and name it of index.php.


In this code we use action="action.php" then these control value send to index.php page We reterive these value on index.php page and can print it. Now make another page action.php for reterive these values

====================================
To Retrieve the value of form
For reterive value of Form tag use super global variable like $_GET and $_POST
$_POST['fieldname']         when method is post on form tag.
$_GET['fieldname']           when method is get on form tag.
====================================

This the code to retrieve the value of the form index.php

<html>
<head>
<title>test1</title>
</head>
<body>
<?php

$user=$_POST['username'];
echo $name;

?>

</body>

</html>

Save this script action.php

How to use get method?

a.php

<html>
<head>
<title>exercise1</title>
</head>
<body>
<form name="frm" action="b.php" method="get">
Enter name:<input name="name" type="text"/><br />
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

v.php

<html>
<head>
<title>exercise1</title>
</head>
<body>

<?php

$name=$_GET['name'];
echo $name;

?>
</body>
</html>

isset()

isset is very usefull function when you send value of the form to the server and reterive value.
isset function is use to check variable exists or not exist.

 This return true if variable exists otherwise this return false.

Why we use isset function and benefit of isset function.


When we send value of the server we check $_POST['fieldname'] in isset function. when we click on submit button then this variable exits on page and write code inside this section. if variable exits our code run otherwise code not run.
 if we are not use isset function then code is run without submit the page to another page.

<?php

if(isset($_POST['submit']))
{
echo $_POST['name'];
}

?>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form name="" action="" method="post">
<input name="name" type="text"><br>
<input name="submit" type="submit" value="Submit" />

</form>
</body>
</html>
Read More

If else statement in php

if statement is use to check condition if condition is true then body of your code will be  execute.

Syntax
if (condition)
{
Code body
}

Exercise 1:

<?php
$x=20;
if($x>0)
echo "Number is true";
?>

Output
===============

Number is true
===============
if else statement

if else statement is use check the condition, if condition is true then the result will be execute,else if the condition is false.

Syntax

if (condition)
{
Code;
}
else
{
Code;
}

Exercise 2:

<?php

$x=25;
if($x>0)
echo "true";
else
echo “False”;
?>

Output
===============
true
===============

elseif statement

if you have one more condition then use elseif statement.

Syntax:

if (condition)
{
Code;
}
elseif (condition)
{
Code;
}
else
{
Code;
}


Exercise 3:

<?php

$x=25;
$y=45;
if($x>$y)
echo "First Number is Greater";
elseif($x<$y)
echo "Second Number is Greader";
else
echo "Both Number is equal";

?>

Output:
====================
Second Number is Greader
====================
Read More

PHP Variable

Variable is just like a container for data. In PHP, there are two type of variable. Predefine variable(SuperGlobal Variable) and User define Variable.

SuperGlobal Variable
 This is predefine variable and these variables are automatically available to any PHP program.  There is no need to declare and define these variable in the program.And this re the example of superglobal variable

$_GET
$_POST
$_COOKIE
$_SESSION
$_FILES
$_ENV
$_REQUEST
$_SERVER

2. Define Variable
 This variable is declare and define

Example:
$x=34;
$x is a variable and the value of $x is 34 and 34 is a data and this data store in variable $x.
Code to print value of $x

echo $x;

here the echo statement print variable data.
===================
output
30
===================
another statement to print the value of $x:
echo "Number is $x";

output
===================
30
===================

Exercise 1:
<?php
$x=60;
echo $x;
?>
Output
===================
60
===================
Exercise 2:
<?php
$x=20;
echo "Number is $x";
?>
Output
===================
Number is 20
===================


Exercise 3:
<?php
$x=10;
$y=20;
$ans=$x+$y;
echo "Answer is $ans";
?>
Output
===================

Answer is 30
===================
Read More

What is PHP?

What is PHP?

PHP is basically use for web developing dynamic website.
Example of dynamic website are facebook.com,google.com etc.
About Web Development

Website has two type which is Static web site and Dynamic website.

-Static Website
In Static website webpage alway show in the same page content.
we use html and css for create static webpage.you can use static webpage
like company profile website.

-Dynamic Website
In Dynamic website the webpage content change automatically.
We use php with html for create dynamic page.
php work with mysql and change webpage content automatically.
php work with server base you can use xampp or wamp.
Advantage of PHP

PHP is openspurce software. For PHP Software,we can download xampp and wamp.
We can run PHP Script to many Operating system, like Windows,Linux,Unix,mac and more.
We can run PHP Script to many server, like Apache server.
We can use many database, like MySQL.
Download xampp

-Go to you browser
-and search for xampp or wampp or
-Copy and paste this url http://www.apachefriends.org.
To install xampp

-Double click on xampp installer
-After Successfully Install. Open xampp Control Panel.if the control panel not show after installing just go to windows key and search xampp control panel.
-Click on Apache and Mysql and also click on Start in front of Apache and Mysql then close xampp Control Panel.
PHP Tags

This is the correct open and close syntax of php.
<?php
//coding here..
 ?>
This is the sort tag of php
<?
//Coding here
?>
How to write PHP Code

In php you can use any editor software like notepad,wordpad,etc..
Much better to use Dreamweaver for beginners to view the color coding and easy to find the errors.

How to use Dreamweaver?
 1.Download Dreamweaver any version or go to adobe.com
 2Open the software and Double Click PHP.

Now you can use this Code
Simple Script:

<?php
echo "Hello World";
?>
=====================
Output:
Hello world
=====================

after encoding this code save it to htdocs to find htdocs follow this path C://xampp/htdocs
and name it anyfilename.php
Easy way to find htdocs:
Go to my computer and go to drive C: and find xampp folder click this and find htdocs

To run this code:

go to browser google chrome or any browser like firefox etc.
next follow this path localhost/anyfilename.php
Now you can see the output "Hello world"
Read More

Patients With Doctors



Title: Patients With Doctors Recorder
Language : PHP,ajax,javascript
Tags:
     PHP
     Ajax
     Javascript
     Jquery

Features:
  Management
    -Add patient and Doctor
    -Update patient and Doctor
    -Delete patient and Doctor
    -Search patient and Doctor

System Requirements:
  -Xampp 1.7.3 or below
  -Chrome,Firefox,Opera. etc.

How to Install?
 -Download the following files by clicking download below
 -Extract the zip files to htdocs(this is the path: C://xampp/htdocs)

Create Database
 -Go to your browser ans type localhost/phpmyadmin
 -Click Tab Import and Browse the SQL file from lib folder this is the file name (dbdoctor.sql)
Read More

Get updates

Twitter Facebook Google Plus LinkedIn RSS Feed Email

Get Free Updates in Your Email


Enter your email address:

Popular Posts