How do i start learning php programming?
Learn PHPPHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. Show
PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. Start learning PHP now » Easy Learning with "PHP Tryit"With our online "PHP Tryit" editor, you can edit the PHP code, and click on a button to view the result. Example
echo "My first PHP script!"; Try it Yourself » Click on the "Try it Yourself" button to see how it works. PHP ExercisesPHP ExamplesLearn by examples! This tutorial supplements all explanations with clarifying examples. See All PHP Examples PHP Quiz TestLearn by taking a quiz! This quiz will give you a signal of how much you know, or do not know, about PHP. Start PHP Quiz! My LearningTrack your progress with the free "My Learning" program here at W3Schools. Log into your account, and start earning points! This is an optional feature. You can study W3Schools without using My Learning.
PHP ReferencesW3Schools' PHP reference contains different categories of all PHP functions, keywords and constants, along with examples. Kickstart your careerGet certified by completing the course Get certified w3schoolsCERTIFIED.2022The PHP guide for beginner developers.Do you want to learn PHP, even if you have no experience? I’m going to show you the exact steps to go from absolute beginner to PHP developer quickly and easily. Let’s get started. Contents
Before you begin.In this tutorial I’m going to guide you through all the steps to become a PHP developer, starting from the very beginning. I’ll show you which tools to install on your computer, which topics to study and in which order, and the important PHP documentation pages to read. If you prefer an easier, faster and more efficient approach, consider enrolling in my Jump Start course. In Jump Start I take care of explaining every single detail, as well as providing plenty of code examples to make it all super
clear. If you prefer to follow this guide for a more “do-it-yourself” approach, then keep reading. Step 1: your study environment.You need two things to start coding in PHP:
Install a local development environment. To run a PHP script, you need an interpreter that understands and runs the code. When you open a PHP webpage online, the remote web server acts as the PHP interpreter executing the PHP code and sending the output to your browser. A local development environment, or LDE for short, is a software package that lets you run PHP scripts on your computer. It provides you with everything you need to develop PHP applications: the PHP interpreter, a web server, a SQL database (usually MySQL/MariaDB) and other utilities like PhpMyAdmin. There are many free LDEs you can choose from, including:
If you’re not sure which one to go with, I suggest you try XAMPP because it’s easy and fast to set up. This is how the XAMPP control panel looks like: Install a code editor. A code editor is an advanced text editor that helps you write your code. Code editors provide useful functionalities such as:
Popular code editors include Atom, Brackets and Notepad++. For example, here’s a screenshot of a PHP script opened with Atom: Atom and Brackets are modern and simple editors.
Side note: There are also more
advanced editors called IDEs (integrated developers environments), such as Eclipse, Visual Studio Code, Netbeans, and more. Step 2: your first PHP page.Before you write your first PHP page, it’s worth spending just a few minutes reading about the language basics. Here are two pages from the official PHP documentation that I want you to read:
All right, now it’s finally time to write your first PHP Hello World script. Start your local development environment and make sure the web server is running. Then, open a web browser and type localhost in the URL bar. You will see the local web server’s homepage. If you are using XAMPP, the page will look like this: Where to save your PHP scripts. Your PHP scripts must be placed inside a directory called webserver root. This directory is usually the htdocs directory located inside the development environment’s own installation directory. In XAMPP, you can open this directory from the XAMPP Control Panel by clicking on the Explorer button (this will open the XAMPP main directory), and then opening the htdocs directory: Remember: you must save your scripts in this htdocs directory. Now open your code editor and paste the following PHP code:
Note: every PHP script must start with the tag. Save the file inside the htdocs directory as hello_world.php (you can use any file name you want, just be sure to use the .php extension). Then go back to your web
browser and open the URL: Congratulations, you just created your first PHP page! Now I suggest you read the following page to learn about a few important details:
If you have any doubt, or if you need help running your development environment, leave a comment or join my Facebook group Alex PHP café. Now let’s dive a little bit more into the language. Step 3: variables and operations.If you have some experience with any programming language, I’m sure you already know
what variables are. A variable is a placeholder for a value. Variables can store texts, numbers, Booleans (true / false), and more complex types such as arrays and objects. PHP variables start with a dollar sign: $ For example:
Here’s a useful PHP documentation page about variable types (2 minutes read):
You can perform many operations on variables. Including:
Here are a couple of simple examples:
Before moving on, I want you to read the following PHP documentation pages about variables and comparison:
It’s perfectly fine if you don’t remember everything. Your goal is to discover what you can do with PHP and understand its potential. Step 4: functions.Functions are one of the basic tools of programming languages. A function is identified by:
Functions perform operations on the passed arguments and then return a value back. Here are a couple of examples:
You can use the many functions provided by the PHP library, as well as make your own functions. Here’s how to define and use your own function:
This is the output:
Before moving on to the next section, read the following PHP documentation pages about functions:
Step 5: control structures.With PHP, you can execute a code block conditionally depending on specific factors. For example, you can decide whether to display an HTML string depending on the value of a variable. The PHP tools that let you make such decisions are called control structures. By using control structures you can implement two fundamental programming patterns: conditional execution and loops. Conditional execution means that a piece of code is executed depending on a value. The main control structure for conditional execution is the IF/ELSE block. For example:
Loops let you repeat the same piece of code a specific number of times, or until a condition is met. The most common loop control structures are WHILE loops, FOR loops and FOREACH loops. Here are some examples:
Now, I want to read the following PHP documentation pages to learn about control structures:
Step 6: the request string.Data is sent from the web browser to the PHP script by using the Request String. The request string is a set of key=value pairs called request parameters. The key is the name of the parameter, and the value is a text string value associated with that parameter. The request string can be sent in two ways:
In every PHP script, the GET parameters are automatically available into the special array $_GET. $_GET is an array with string keys. Each element of $_GET has the parameter’s name as key and the parameter’s value as value. For example, let’s say that you have the following URL request:
And the print_get.php script contains the following code:
This is the output you’ll get:
POST data is available in the $_POST array (instead of $_GET). POST is often used for HTML forms. For example, let’s say that you have this HTML form that uses the POST method:
To print the data from that form, you need to look into the $_POST array. Like this:
Output:
The $_REQUEST array contains the elements from both POST and GET data. In other words, it includes the elements of both $_POST and $_GET. If you want your PHP script to work with any request method, you can use $_REQUEST instead of $_POST or $_GET. Now go and read the following PHP documentation pages about $_GET, $_POST and $_REQUEST:
P.s. In the Jump Start course everything is explained by me, without the need to read the PHP documentation pages. I also provide many more examples as well as in-depth explanations. Step 7: Sessions.PHP uses Sessions to keep track of consecutive remote user access. Sessions are used extensively for user authentication to keep track of user logins, in e-commerce websites to keep track of purchases and in many other scenarios. Almost every PHP-based website uses Sessions. It’s a good idea to learn Sessions from the start, because they will let you write stateful websites very easily. Next steps?At this point, you already have a solid background to build your own PHP apps. Of course, there is much more about PHP than just the basics. When you feel ready to dive into more advanced topics, I suggest you start from these three topics:
Object-Oriented Programming To get started, you can look at the following tutorials:
Databases Here’s my complete guide about using PHP with MySQL:
Security Here are some tutorials about security topics:
Conclusion.In this step-by-step guide you have learned how to get started with PHP, including how to install a development environment and a code editor. Then, you went through all the basic PHP functionalities such as variables, functions, control structures and Sessions. Make sure to leave a comment and let me know your personal experience with learning PHP. P.s. If this guide has been helpful to you, please spend a second of your time to share it. Thanks! Alex Do You Want to Improve Your PHP Skills?Grow your PHP skills every week, with my free weekly PHP tips.Image copyright: Remote learning vector created by vectorjuice – www.freepik.com How do I start learning PHP?PHP Tutorial. Easy Learning with "PHP Tryit" With our online "PHP Tryit" editor, you can edit the PHP code, and click on a button to view the result. ... . PHP Exercises. Test Yourself With Exercises. ... . PHP Examples. Learn by examples! ... . PHP Quiz Test. Learn by taking a quiz! ... . PHP References.. What should I learn first for PHP?Step 1: Learn HTML and CSS
Before you learn PHP, you should take some time to learn HTML and CSS. HTML and CSS are used to define the structure and style of a web page, respectively. They are the fundamental building blocks that make up the web.
Can I learn PHP alone?php is a stand alone language. it's a must for server side content creators. you can learn python or any other language but you'll have to leaem the framework that connects it to the web so in my opinion learninh php is very beneficial. if you want to connect it to a database use sql.
|