The first program in PHP

I want to start with the first PHP program. I installed xampp and looked at the code samples. How to start writing custom code to create web pages. Where to begin. I need to write a text file as code and open it in Explorer, as we did in HTML. Thanks in advance.

+7
php
source share
10 answers

You can use almost any text editor that you like, but one with syntax highlighting simplifies the work. Notepad ++ is a convenient editor for Windows and has syntax highlighting for various languages, including PHP, HTML, CSS and SQL.

Look at some tutorials - this is often easier than wading through documents - although documents are , of course, necessary.

There is a good step-by-step guide for beginners at tizag.com :

PHP Tutorial - Learn PHP

Once you learn the basics, there are many more tutorials. I really like some of the PHPro tutorials, but there are many others. Here are some 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
HTML parsing with PHP and DOM
Introduction to PHP Regex

Note. I placed the regular expression tutorial after the SimpleXML tutorial for a good reason. If you ever want to parse HTML with regular expressions, just read this . If you are still not sure, read it again . :-)

When you get into the database (I assume 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 quickly go to mysqli :: to prepare prepared statements . You will probably save yourself a ton of problems if you consider dynamic SQL as a training exercise, but then move on to prepared instructions for everything else.

Try to familiarize yourself with some common PHP security issues and what can be done to mitigate them.

It is a good idea to develop consistent naming standards .

When you start writing more complex sites, you might want to take a look at the mechanisms of templates. There is a degree of disagreement with them, since PHP can be used directly as a template system. However, I had a good impression of Smarty , and I found that it helps me to distinguish the application logic from the displayed code.

Patterns bring me into the framework. They do a lot of website writing. There are many available, and everyone will have their own opinions about which is better. Therefore, instead of offering one, here is a link to a list of popular ones:

http://www.phpframeworks.com/

By the time you get to this stage, you will probably find using the debugger very convenient. A good starting point (it works and it is free) is a combination of Eclipse with XDebug - but there are other options.

+13
source share

You need to find the root folder of your xampp (possibly something like C:\Program Files\xampp\htdocs on Windows) 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, for example:

 <?php echo 'Hello World'; ?> 

Save and view it through the browser ( http: //localhost/yourfile.php ).

+12
source share

To a large extent ...

Open notebook

  <?php Print "Hello, World!"; ?> <?php Echo "Hello, World!"; ?> 

Save as filename.php and exit.

+3
source share

Perhaps start here on the PDF Documents page.

+2
source share

You cannot open it, as you did with html files, by clicking the file. You should put your php file in the xtdpp htdocs folder. Then open your browser and go to http: //localhost/myscript.php "to open it :)

+2
source share

Paste this into index.php

 <?php print "Hello World!"; ?> 

And your off :)

You can easily insert this into the markup as follows:

 <html> <body> <h1><?php echo "Hello World"; ?></h1> <p><?php echo $content_variable; ?></p> </body> </html> 
+1
source share

Instead of Hello World, try the following:

 <?php phpinfo(); ?> 
+1
source share

Download Notepad ++, which is a free gui that helps you put together its main advantage of color syntaxes over Notepad itself. But yes, the theory describes your respective code as the guys mentioned above, and browsing in the selected browser. Your code will be available via http: // localhost in your browser when you are ready to view it. Give it a start, then go to the side of the things database, where its more interesting world is.

Welcome to the world of PHP.

0
source share

I never get tired of recommending NetBeans as an incredible IDE for PHP.

As for your question, @Mike's answer is quite complete. I would add that learning some patterns (smarty, twig) after learning the basics or, better yet, a complete PHP framework like Zend or CodeIgniter (easier). This is really important. This makes the code much more convenient and understandable. It will take more time, but you will be grateful when you take the old project.

In addition, I want to focus on object oriented PHP and PDO.

0
source share

I will recommend you Notepade ++, which will help you copy its main advantage of color syntaxes compared to Notepad itself.

0
source share

All Articles