I wanna start with first program in PHP. I have got installed xampp and had a look at sample codes. How to start writing my own code to build web pages. Where to start with. Do i have to write a text file as code and open it in explorer like we did it in HTML.Thanks in advance.
-
11seriously? 7 up votes? – coolgeek Jul 12 '10 at 14:57
-
1You can use notepadd++ if you want yes and you have to save the file in htdocs and access it in your browser http://localhost/yourfile.php [just like this](http://www.elcaro-guide.com/php-blog/first-lesson-in-php-htdocs-folder-writing-my-name-in-php) – SMK Jun 27 '14 at 17:27
10 Answers
You can use almost any text editor you like, but one with syntax highlighting makes things easier. Notepad++ is a handy little editor for Windows, and has syntax highlighting for many different languages, including PHP, HTML, CSS and SQL.
Have a look at some tutorials - it's often easier than wading your way through the docs - although the docs are, of course, essential.
There's a good step-by-step beginners guide on tizag.com:
Once you've mastered the basics, there are plenty more tutorials available. I quite like some of the tutorials on PHPro, but there are many others. Here's a few PHPro articles to get you started:
Object Oriented Programming with PHP
Introduction to PHP Sessions
Introduction to PHP and MySQL
Introduction to SimpleXML with PHP
Parse HTML with PHP and DOM
Introduction to PHP Regex
Note: I put the regex tutorial after the SimpleXML tutorial for good reason. If you ever get the urge to parse HTML with regular expressions, just read this. If you are still not sure, read it again. :-)
When you get to database stuff (I'm assuming MySQL for the sake of simplicity, but this applies equally to other DBMSs), warm yourself up with a little dynamic SQL and mysql_real_escape_string. Then swiftly move on to mysqli::prepare prepared statements. You will probably save yourself a whole lot of problems if you treat dynamic SQL as a learning exercise, but then move onto prepared statements for everything else.
Try to become familiar with some of the common PHP security problems, and what can be done to mitigate them.
It's a good idea to develop consistent naming standards.
When you start writing more complex sites, you may want to look into template engines. There's a degree of disagreement about these, as PHP can be used directly as a template system. However, I've had good experiences with Smarty, and find that it helps me to keep the application logic separate from the display code.
Templating brings me onto frameworks. They take a lot of the grunt work out of writing web sites. There are many available, and everyone will have their own opinion about which is best. So instead of suggesting one, here's a link to a list of popular ones:
By the time you get to this stage, you'll probably find the use of debugger very handy. A good starting point (it works, and it's free), is a combination of Eclipse with XDebug - but there are other choices.
-
many thanx for this helpful advices. I want to start learning php and I find this answer to give me what I need. :) – palAlaa Apr 09 '11 at 06:55
You need to find the root folder of your xampp (probably something like C:\Program Files\xampp\htdocs
- in Windows that is) and create a new empty file there. Rename its extension to .php
and edit the file.
Start with something small, just to test the installation, such as:
<?php echo 'Hello World'; ?>
Save and view it through your browser (http://localhost/yourfile.php).

- 9,122
- 5
- 34
- 68
pretty much...
Open Notepad
<?php
Print "Hello, World!";
?>
<?php
Echo "Hello, World!";
?>
Save as filename.php and away you go.
You can't open it like you did with html files via clicking the file. You gotta put your php-file in the htdocs-folder of xampp. Then open your browser and go to "http://localhost/myscript.php" to open it :)

- 5,754
- 1
- 18
- 25
Stick this in an index.php
<?php
print "Hello World!";
?>
And your off :)
You can easily embed this into markup as follows:
<html>
<body>
<h1><?php echo "Hello World"; ?></h1>
<p><?php echo $content_variable; ?></p>
</body>
</html>

- 3,209
- 23
- 26
-
you're probabaly going to confuse him with your print ‘Hello World!’; as they're not valid quotes. – Kieran Allen Jul 12 '10 at 14:09
I will recommend Notepade++ to you which will help you code with its main advantage of colour syntaxes compared to Notepad itself.
Download Notepad++ which is a free gui which will help you code with its main advantage of colour syntaxes compared to Notepad itself. But yep the theory is write your relevant code like the guys mentioned above and preview within your choosen browser. Your code will be accessible via http://localhost in your browser when you ready to preview. Give that a start then move on to the database side of things where its a more interesting world.
Welcome to the world of PHP.

- 1,017
- 6
- 12
I never get tired of recommending NetBeans as an incredible IDE, for PHP as well.
As for your question, @Mike's answer is quite complete. I would add learning some template engine (smarty, twig) after you learn the basics, or better yet a full PHP framework like Zend or CodeIgniter (more lightweight). This is really important. It makes the code a lot more maintainable and easy to understand. It'll take more study but you'll be thankful when you pick up an old project.
Also, I want to make an emphasis on Object Oriented PHP and PDO.

- 7,947
- 15
- 63
- 74