View Aayushi  Sinha 's Profile
What is the Basic PHP Syntax ?
PHP is a server side scripting language that, very often along with databases created with SQL, can create dynamic webpages.

* Start a PHP File

The very first step when coding with PHP is to start with a blank file. I am using notepad. I will go to file save and call it test.php. Make sure that you add the extension .php at the end.

* Create a Tag for PHP Code

Now we need to create a tag letting the server know that there is php code. So type a bracket, question mark,then php. Following this will be our code.

At the end of the code, we need to add another question mark and a closing bracket to state that the php statement is complete. Anything that is outside of this tag will be read as HTML. If you want, you can leave out the php text in the tag and just start with a bracket and question mark.

* Add a Comment to the PHP

Comments are always a good idea when you want to explain what a function or piece of code does without it being displayed. To create a comment, you can type two slashes and then a comment on one line.

Alternatively, you can write your comment after the number sign. If you have a large block of text you can type a (IS THIS BACK?) slash followed by an asterisk. Then write your block of text and end it with another asterisk and slash.

* Output Text in PHP

Now, let's output some text. All we need to do is add the word echo followed by our text in quotes. I will write Hello World. If you want to add another line of text, just add a semicolon after the quote and, on the next line I will type echo again and, in quotes, Hello Again.

* Upload the PHP File

I will save this file and upload it via FTP to my web server. If I open up my Web browser and type in the URL where that file is saved, we will see our text. Notice that there is no line break between the two statements. If I go back to my code I can add an echo in between them. In quotes I will add an html break tag. Once I save and upload the file again, I can hit refresh and there is the text on the second line.

* Variables in PHP

If you have used variables in other languages, then PHP will seem familiar. Just type a dollar sign and make up a name for your variable. I will create $text1. To give this a value I'll insert an equals sign and then Hello World in quotes again. I can create another variable $number that is an integer. I can write a number, 312 and don't need to put it in quotes.

There is a lot more you can do with PHP but this should help give you a feel for what to expect when working with PHP.
Asked by Aayushi Sinha | May 13, 2013 | Report this Report abuse |  Reply now
Replies (1)
View Ragin  Dwivedi 's Profile
Not cleared fully !!! I think some more steps you should write
May 17, 2013 | Report this Report abuse
SiliconIndia About Us   |   Contact Us   |   Help   |   Community rules   |   Advertise with us   |   Sitemap   |   Question & Answer
News:       Technology   |   Enterprise   |   Gadgets   |   Startups   |   Finance   |   Business   |   Career   |   Magazine  |   Newsletter   |   News archive  
Cities:        CEO   |     Startup   |   Mobile   |   CIO   |   Women   |   BI   |   HR   |   SME   |   Cloud   |   Marketing   |   QA   |   Java   |   Web Developer  
Community:      Members   |   Blogs   |   Mentorship   |   Indian Entrepreneurs   |   Gyan   |   Advice   |   Community   |   Find   |   Events   |   CXO Insights  
Job Board:      Jobs   |   Freshers   |   Companies   |   HR Speak   |   Forum  
Online Courses:   Web Developer   |   Java Developer   |   CCNA Training   |   SEO   |   SAS   |   SQL Server 2005   |   J2EE
Education:   MBA   |   MCA   |   Engineering   |   Overseas Education   |   Training Institute
Life:          Real Estate   |   Travel   |   Finance   |   Gadgets   |    Products   |   Movie Reviews   |    Jokes   |   Videos 
Send your and help us continue to improve SiliconIndia
© 2013 SiliconIndia all rights reserved