Showing posts with label PHP TUTORIALS. Show all posts
Showing posts with label PHP TUTORIALS. Show all posts

Tuesday, 28 March 2017

Working with Variables in PHP

 In PHP you can do some addition with the PHP addition operator , +, to add numbers together like this:
<html>
<head>
<title>Variable in PHP
</title>
</head>
<body>
<h1>
The Answer:
</h1> <br>
<?php
echo "Answer" ,1+4+6,".";
?>
</body>
</html>
We run first time this, it display the message
The Answer:
Answer:11

Another way of variable representation in PHP. In PHP variable name begin with a $ sign followed by a name and that name must start with a letter or an underscore not a number. foe example to store the number of users in p you might have a variable named $p; the number of users in q and r might be in variable $q and $r. you could place data in those variable at run time and add those three data items together also at run time.

<html>
<head>
<title>Variable in PHP
</title>
</head>
<body>
<h1>
The Answer:
</h1> <br>
<?php
echo "Answer" ,$p+$q+$r,".";
?>
</body>
</html>
at run time the value inside each variable is substituted for that variable so if $p=1, $q=4, and $r=6, the preceding line of PHP code would look like this to PHP:
<?php
echo"Answer:",1+4+6,".";
?>
and so you get "Answer:11"

Monday, 27 March 2017

PHP here document(heredoc)

Another Way of displaying text that you should be aware of, and that's using PHP "here" documents.
A heredoc is just same text inserted directly in a PHP page, between two instances of the same token.

Token:-
              Token is a word such as END then you can display the text in a here document by using the syntax echo<<<TOKEN
Where TOKEN is the word that begins and ends the here document.
Example:- 
<HTML>
<HEAD>
<TITLE>
Display text from PHP
</TITLE>
</HEAD>
<BODY>
<H1>Display text from PHP</H1>
Here's What PHP has to Say:
<BR>
<BR>
<?php
echo<<<END
This example Uses
"here document" Syntax to display all the
text until the ending token is reached
END;
?>
</BODY>
</HTML>
Browser view:- 


And you can see what this produces in a browser. The text in the here document was display in the browser.
Using the token END is by no means necessary; here's the same here document with the token FINISH:

echo<<<FINISH
This example uses
"here document" syntax to display all
the text until the ending token is reached.
 

Wednesday, 22 March 2017

Control Characters in PHP

\n :- New Line Character

for example:

echo"Welcome \n";
echo"to PHP";

\r :- Carriage Return
\t :- Tab
\\ :- Display a \
\$ :- Display a $
\" :- Display a "
\0 to \777 :- Display s Character corresponding to a hexadecimal (base 8) code.
\x0 to \xff :-Display a character corresponding to a hexadecimal (base 16) code.

Monday, 20 March 2017

echo statement in PHP

echo statement is used to display the text on the browser. or get output on browser.The echo statement can be used with or without parentheses: echo or echo().
You can pass text to display to the echo statement, using single or double quotes.
you can also directly pass the numbers to echo if you want , no. quotation marks needed.

For example:-

<html>
<head>
<title>Displaying text using echo statement</title>
</head>
<body><h1>Displaying text using echo</h1>
<br></br>
<?php
echo "first statement";
echo 'second statement';
?>
  </body>
</html>
browser view is:-

Displaying text using echo
first statement
second statement

Saturday, 18 March 2017

Creating a PHP Page

PHP page will be a very simple One. You can start this page with the Special Markup that indicates You are about to start using PHP and that Markup looks like this
<?php
.
.
.
.
.
?>
for Example:-
<?php
phpinfo();
?>
Here PHP Code Starts<?php and end with ?> and phpinfo(); is a library function. for inserting PHP  logo we use <img src="php-med-trans-light.gif"> statement.
Printing the Some text on the Browser:-In PHP for printing a statement we use echo statement
For Example:-
<html>
<head><title>displaying text on the browser using echo statemant</title>
</head>
<body>
<br>
<?php
echo "Welcome to the PHP world";
?>
</body>
</html>
In Your browser now Show:-

Welcome to the PHP world
 

Friday, 17 March 2017

What is PHP

PHP Stands for -
                    "PHP:-Hypertext Preprocessor" But Its original name PERSONAL HOME PAGE.
PHP is the  server_side programming language that's taken the web world by storm
PHP is far and Away the most popular programming language for use on web servers. PHP able to do some easy programing on the web server, creating everything from online database to guest books from customer schedulers to chat rooms from file uploading tools to shopping carts, Its all possible with PHP.

PHP at that time was called personal home page or personal home page tools. At that time as you might expect php was very simple and could be used to creete web page hit, counters, guest books.

Creating PHP page/Document: Some step for creating PHP page.
Step1.Open text editor like NOTEPAD, WORD PAD, etc.
Step2.Write PHP code in text editor.
Step3.Save file with Extension .PHP.

Simple PHP document:-PHP and HTML Together

<HTML>
<HEAD><TITLE> PHP and HTML DOCUMENT</TITLE>
</HEAD>
 <BODY><H1>DOCUMENT USING PHP AND HTML</H1>
phpinfo FUNCTION
<BR>
<?php
phpinfo();
?>
</BODY></HTML>
 
the above document save file name phphtml.php in php Extension we used .php.