
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
In this lesson, you create your first PHP file and learn how PHP integrates with HTML, making every HTML code also a PHP code.
You explore how PHP blocks (marked with <?php and ?>) within an HTML file can run PHP commands, to generate dynamic outputs on your webpages, such as displaying random numbers.
Additionally, you come to understand the precise nature of PHP and how even minor mistakes in your PHP code can cause your entire program to fail.
In this lesson, you gain a practical understanding of how PHP generates HTML, enabling you to witness firsthand how browsers interpret and display this code.
You learn the intricacies of PHP's ability to create any text, including HTML, and how this influences the way web browsers present the resulting content.
Moreover, the lesson guides you through using PHP in combination with CSS to dynamically design and modify web pages.
In this lesson, you explore dividing your PHP code into several files which can help simplify the deployment of HTML websites and create shared HTML structures.
You learn about the 'include' command in PHP, which allows you to import and execute code from other files.
You understand that even non-PHP files (such as .txt files) can be included and executed as PHP code, although it’s best practice to use .php extensions.
In this lesson, you learn about variables in PHP and how they can be used to store and manipulate data.
You see how to create variables using the dollar sign ($), set their values with the equals sign (=), and output their values using the echo statement.
You also learn how variables can be useful for dynamic web page creation, allowing you to easily change content in multiple places by modifying a single variable.
Through this lecture, you're introduced to the project of developing a restaurant website using PHP to transform a single-page site into a multi-page one.
You learn basic HTML and CSS coding, including the use of tags, creating a navigation bar, and the insertion of images and text.
The lecture also touches on the limitations of HTML when it comes to adding new pages, setting the stage for utilizing PHP to simplify this process.
In this lecture, you learn how to facilitate website navigation by adopting PHP instead of HTML.
You understand how to rename .html to .php, create a new folder for 'includes', and initiate an include command.
Finally, you grasp how PHP codes can enable easy changes across all website pages, offering a solution to repetitive manual changes in navigation.
In this lecture, you learn how to optimize a website using PHP to alter the background image and title based on the webpage you're on.
You discover how to define variables before including headers, allowing these variables to be output in different files.
You're also taught how to manage errors, ensuring that PHP configurations complain when variables aren't existing.
The lecture ends with an exercise, encouraging you to add a new page on your own by integrating the learnt PHP process.
In this sample solution, you learn about how to transform HTML pages into PHP to allow the execution of PHP code.
You are shown how to change the file extensions of HTML to .php, enabling you to incorporate these files into your navigation.
The process of copying structures from other pages, inserting new configurations, and including page elements like headers and footers is demonstrated, reinforcing how PHP can simplify website extension and management.
In this lecture, you learn about potential problems that can occur in PHP due to syntax errors.
This includes parse errors that occur when PHP cannot understand the structure of a code, causing it to fail in execution.
You are also taught about warnings, which flag up problems but do not halt program execution, as well as fatal errors which indicate serious problems resulting in program termination.
In this PHP tutorial, you learn about strings and how they work.
You understand that strings are collections of characters and can be manipulated with a concatenation operator.
The lecture also teaches you about string handling, including escape sequences for problematic characters.
In this lecture, you learn about defining strings in PHP using double quotes.
Double quotes allow you to include single quotes within the string without escaping and enable certain operations that aren't supported in single quoted strings, like accessing variables inside the string.
However, you should use single quotes when possible to avoid unwanted behaviours and only use double quotes when necessary.
In this PHP lecture, you learn how to work with numbers and perform calculations without the need for quotes.
You understand how variables can be used for calculations, how PHP tries to automatically convert types, and the associated potential errors if non-numeric strings are used in calculations.
Lastly, you learn that PHP seamlessly works with floats (decimal numbers), offering ease in performing diverse mathematical operations.
The lecture covers the importance and uses of the vardump function in PHP.
You learn how to invoke the vardump function to give better insight during debugging than an echo would.
The function allows you to ascertain the type and details of variables, how special characters and non-English characters may need additional space, and how the function works with numbers, string conversions, and variables.
In this lecture, you learn about the fundamental concept of booleans in PHP, which represent either a true or false value.
You discover how booleans are created through various comparisons, such as larger than, smaller than, equals, and not equals, with and without type checking.
Furthermore, you understand the importance of using strict comparisons to ensure type and value equality, which helps to avoid potential programming problems.
In this lecture, you learn about the 'if-construct' while programming PHP which determines if a certain block of code executes.
You are taught how to use simple booleans or create an evaluation expression to control the executed code.
You also learn how to include multiple lines of code in one block and the usage of curly brackets when writing the if-construct.
The lecture educates you on the use of 'if', 'else', and 'else if' statements to create conditions in PHP that manipulate server output based on server status.
You also learn the importance of ordering these clauses appropriately for accurate evaluation of conditions, cautioning you against interrupting the 'if' and 'else' blocks.
Furthermore, it illustrates ways to test the same variable for different values to increase your code's efficiency and flexibility.
In this lecture, you learn about the functions isset and empty in PHP which are used to query the status of a variable.
You find out that isset checks if a variable exists, returning true if it does, and false if it doesn't while empty also checks if the variable exists and whether it contains a value, considering a variable empty if it doesn't exist or contains a zero.
Additionally, it's taught that you can use unset to completely remove a variable.
This lecture focuses on PHP alternative syntax, mainly used for embedding PHP into HTML code.
You're taught how to transform the classic syntax into the cleaner alternative syntax for conditional statements, making HTML structure evident, and helping differentiate between different uses of curly braces within PHP.
It's suggested that alternative syntax is ideal for generating HTML and standard syntax for implementing logic.
In this lecture, you're learning about working with Boolean operators in PHP.
You're taught how to flip Booleans, logical AND, OR, and XOR.
The lecture emphasizes that these operators are usually used within conditions in if statements, and highlights how to create expressions that evaluate to a Boolean.
It provides greater flexibility for writing if statements and is central to combining Booleans and expressions.
In this lecture, you're asked to improve your restaurant project by adding functionalities to the navigation bar that shows which page is active, provide a default background image for pages that do not specify one, and create a default title for pages that do not provide one.
The alternative PHP syntax is highlighted as it can be used to toggle certain attributes within an HTML tag.
This Sample Solution introduces ways to troubleshoot and refactor your code to mitigate errors and enhance web page flexibility.
You learn tactics such as removing variables, mitigating warnings, and ensuring all your content still appears through the use of default settings.
This section of the sample solution demonstrates how to highlight the active menu item on your website by toggling a CSS class named active.
It demonstrates how to use a PHP code to highlight the site that you currently want.
It also shows how to use a variable called pageKey to identify which page you are on and apply the active class to it.
In this lecture, you learn about arrays in PHP, which allow you to group multiple values together in one variable.
Arrays help you avoid inconsistencies on your website by enabling you to generate list elements on the fly, so they are no longer fixed.
Furthermore, adding a new element to your arrays automatically updates all parts of your site referring to that array, providing a consistent user experience.
In this lecture, you learn to solve the issue of defining multiple categories on a website using PHP's array function.
You understand how to declare an array, adding items and defining elements within it using echo or var_dump functions.
You also explore how to access individual elements from the array and how to turn these elements into variables.
The lecture also covers the flexibility of arrays in PHP, explaining they can hold any value and offering two ways to declare an array; using either array() or square brackets [].
In this lecture, you learn more about working with arrays in PHP, including how to access, test the existence of elements, and how to handle non-existent elements.
You learn to use 'isset' or 'empty' to test if an element exists, and 'in_array' to check for specific values.
Additionally, you understand how to use 'count' to get the number of elements in an array.
In this lecture, you learn how to modify PHP arrays including how to change, delete, and add elements.
You discover that using 'unset' on an array removes an entry entirely, but does not shift subsequent keys up, leaving the possibility of missing elements.
Lastly, you learn that using consecutive keys when appending elements simplifies your code and makes arrays easier to work with.
This lecture teaches you how to use PHP to run a giveaway by writing code to randomly select a name from a list of subscribers.
You see how to define arrays, use best practices when adding entries, utilize count and rand functions to select a winner, and output this information via var_dump or echo.
In this lecture, you learn about working with arrays in PHP using array functions.
You're taught how to remove duplicates from an array using the 'array_unique' function and how to sort arrays alphabetically with the 'sort' function.
The lecture introduces a variety of other PHP array functions available that you can explore further on php.net or via your code editor's autocomplete feature.
In this lecture, you learn about the for-each loop, a tool in PHP that enables you to repeatedly run a block of code for each element in an array.
Specifically, you delve into its syntax, how to use it to generate HTML code, and its alternative syntax ideal for HTML.
Last but not least, you're given tips on variable naming and handling whitespaces to enhance code readability and design respectively.
In this lecture, you learn about the 'break' and 'continue' keywords to control iterations of for each loop in PHP.
'Continue' allows you to skip an iteration and move on to the next one if the condition is true.
In contrast, 'break' not only ends the current iteration but terminates the whole loop.
Both these keywords work in the PHP alternative syntax, offering efficient control over the loop's execution.
In this lecture, you learn about associative arrays in PHP.
Associative arrays allow you to store key-value pairs in one array, offering an efficient way to access and manage related data.
You also discover how to check if a certain key exists and if its value is not empty.
In this lecture, you're introduced to the manipulation and usage of associative arrays in PHP.
Specifically, you're shown how to add, override, and remove entries, use count to determine the number of elements, and navigate the array using foreach.
Furthermore, you'll learn how to use two useful PHP array functions, array_keys and array_values, to extract the keys and values out of your associative array for further manipulation.
In this lecture, you learn how to manage associative arrays in PHP.
You explore what happens when a new entry is added without specifying a key, with PHP automatically generating a numeric key for you.
The lecture advises against mixing associative arrays with normal arrays, even though it is technically possible, as this can lead to confusion in the code and potential problems later on.
In this lecture, you learn how to add parameters to a URL in a PHP file, an essential skill for creating interactive web pages.
You are taught how to use the $_GET array in PHP to access these parameters and manipulate them within the script, which can include checking if a parameter is empty and printing a parameter's value.
The lecture teaches you how to automatically create a URL link with parameters using PHP.
It explains how to create a hyperlink to a current page and add parameters such as the name of a book.
You also learn to use the HTTP build query function to convert an array into a query string, avoiding potential browser issues or different interpretations.
In this lecture, you learn about integrating parameters into URLs through HTML form elements to interact with PHP scripts.
First, you create a form to submit parameters through GET, exploring ways to generate and submit information via the browser to the server.
Additionally, you examine how to auto-fill an input field following form submission to boost user experience.
In this lecture, you learn about form submission in PHP.
We discuss the limitations of using the GET method for form submission, most notably the security issue of sensitive data like passwords being visible in the URL, and the alternative: the POST method.
Lastly, you're reminded that data transferred through HTTP is unencrypted and warned about the potential for cross-site scripting attacks.
In this lecture, you learn the importance of securing your website against cross-site scripting (XSS) attacks, where malicious input can wrongly be interpreted as code.
Specifically, you learn the necessity of using PHP's `htmlspecialchars` function, which converts special characters to their HTML entities and prevent them from being wrongly interpreted as HTML tags.
Furthermore, you learn how to make this process easier by creating a handy custom function `e`, which does the necessary conversions for you every time you output content, even if it's not user-generated.
In this lecture, you undertake a project to create a recipe selection application, which will allow choosing a recipe from a dropdown.
You initially use PHP's 'include()' function to load the dynamic content, however, this presents a security flaw as it can execute arbitrary PHP code.
To avoid this, you transition to using 'file_get_contents()' function, which loads the contents of a .html file without executing any PHP code, thus enhancing security.
In this lecture, you learn about the importance of secure coding, especially when dealing with user-generated inputs.
We identify and fix a security flaw in our recipe app which allowed access to non-allowed files by checking whether the user's input matches an allowlist before loading the file.
Your task now is to refactor the code to make it more maintainable by converting it to an associative array, which will automate the option menu generation and consolidate all specifications into one array.
In this lecture, you learn how to enhance your code quality by using an associative array in PHP.
This process involves defining your array, looping through it using a 'foreach' loop and generating corresponding HTML options using 'echo' and the 'e' function.
Finally, you discover how to select specific elements from the array using the 'empty' function, ultimately improving the functionality and safety of your code.
In this lecture, you're tasked to create an image gallery using arrays and PHP to enhance flexibility.
You'll commence the project with an empty page and then implement a list of clickable images using the provided project materials.
Remember to consider things like the get parameter in your image.php file, using provided functions, and building the correct path to access your images.
The lecture covers the crucial role the rawurlencode function plays in ensuring filenames, even those with special characters or white spaces, are correctly and safely outputted.
You are also cautioned to only apply the function to filenames, not paths, to avoid compromising the URL's structure.
In this lecture, you learn how to manipulate the display of images with differing aspect ratios using CSS.
The lecture introduces 'object-fit', a property that adjusts how image content fits into an image element, and explains how to use 'aspect-ratio' within CSS to ensure images display at exactly the same dimensions regardless of their original aspect ratios.
Lastly, it suggests that these techniques can improve the design of your image gallery.
The lecture guides you on creating a gallery page in PHP, starting with displaying a series of images using an array, generating image tags, and outputting these on the webpage.
It explains how to handle errors by displaying alt text and how to adjust image paths.
It also adds functionality such as clickable images which then navigate to a new webpage.
In this lecture, you learn how to improve the design of an image gallery using CSS.
You understand how to make an element a block element to style it more easily, using CSS properties to manage the size and spacing of your gallery items.
You also discover how to use flexbox to display multiple elements side by side, manage white space, and align your elements
This ensures your gallery not only functions well but also looks visually appealing.
In this PHP tutorial, you learn how to implement an individual image page within a gallery.
The primary focus is on validating URL parameters against an allow list with image titles, safeguarding against potential cross-site scripting attacks.
Additionally, this lecture shows how to correctly sanitise and format image attributes for display and how to add navigation for a better user experience.
In this lecture, you learn how to check the type of a variable in PHP using functions like var_dump and is_ functions (is_bool, is_numeric, etc.).
You also learn how to handle mixed-type arrays, using is_array to check array entries.
In this lecture, you learn about typecasting in PHP.
You explore a scenario where a fatal error occurs due to multiplying a string with a float and how typecasting helps to define a variable type, thereby avoiding such problems.
You also delve into other ways of typecasting such as casting into bool, float, and array, and discuss how typecasting errors can give more insight into where a problem occurs in the code.
This lecture delves into handling warnings in PHP, particularly those arising from typecasting issues like converting an array to a string due to user input manipulation.
It introduces the use of the "@" symbol to suppress warnings, enhancing application robustness without affecting fatal errors, which remain unsuppressable for critical issues.
This lecture explores the null coalescing operator in PHP, a tool for streamlining the assignment of default values to variables by eliminating the need for explicit checks.
It also covers how to properly combine this operator with typecasting to avoid errors and ensure accurate data handling.
The lecture teaches you the nuances of using the 'include' command in PHP, which is key to maintaining and navigating larger applications.
You learn that PHP searches for the included file first in the folder of the root file, which can lead to confusion if there are files with the same name.
The course provides a solution through using PHP's '__DIR__' constant, ensuring you can reliably navigate to and include the correct file, regardless of the initial directory.
In this lecture, we examine ways to include files in PHP.
You will learn the difference between the include and require commands and why it's essential to use them correctly to prevent errors in your code.
We also delve into how to use the require_once and include_once commands, which ensure files are not repeatedly loaded, helping you maintain a user-friendly and efficient website.
In this lecture, you're introduced to PHP's explode and implode functions.
You learn that the explode function allows you to split a string into an array based on a specified delimiter, creating new array elements at each occurrence.
Conversely, the implode function enables you to merge array elements back into a string, using a specified 'glue' to join them.
In this lecture, you learn about various string functions in PHP.
You explore how to access a single character and get a substring from a string, count the number of characters, check if a string starts or ends with a certain substring, convert strings to lowercase or uppercase, and truncate the beginning or end of a string.
Additionally, you learn how to find a word or characters in a string and understand how some functions are case sensitive.
In this lecture, you explore the nl2br string function in PHP, which converts newline characters into HTML break tags, helping format text for easier readability.
Additionally, you learn to use the str_replace function to replace specific characters or strings within a text.
It's important to use the escaping function before applying nl2br or str_replace to maintain security and prevent problematic characters from interfering.
In this lecture, you'll understand how a web server's configuration can display a directory index, allowing you to navigate within your file system, which is unrelated to PHP.
You will also learn that both `index.html` and `index.php` files are automatically recognized and displayed by the web server, thus eliminating the need for specific PHP files in your URL.
The session teaches you to differentiate between Apache, the web server, and PHP operations, which Apache initiates.
In this lecture, you are taught about nested arrays, using the example of an online language school.
You learn how to create arrays with multiple properties, such as the language course title, description, and flag, instead of using multiple separate variables.
Also, you learn how to manipulate these nested arrays, to access and display specific information from within each sub-array.
In this lecture, you learn how to use nested arrays within a for-each loop in PHP, focusing specifically on going through the outer array layer.
You discover how to output each course from the array and gain knowledge on how to convert the output into HTML code, demonstrating its use in generating custom lists.
The importance of understanding which array your for-each loop is accessing, especially in nested arrays, is also emphasized for the correct application.
In this lecture, you learn how to store additional course information using nested arrays and for each loop within another for each loop.
You are shown how to add topics to language courses and traverse them using array indices and keys.
By the end, you are able to generate convenient HTML code for each course and its respective topics using PHP, highlighting the power and versatility of nested arrays.
In this lecture, you learn to handle inconsistencies in nested arrays, particularly cases where certain array keys may not be defined.
You'll understand the necessity of implementing checks, like the 'if not empty' condition, to prevent PHP warnings and unwanted HTML output.
Lastly, this lecture primes you for the next lesson where you'll learn how to skip an entire course or key during a loop.
In this lecture, you are introduced to the air quality project data and how it is processed.
Through the use of PHP functions like file_get_contents() and JSON_decode(), you learn how to load and decode the data into PHP arrays for easy manipulation.
You also look at dealing with compressed files using .bzip2 and the importance of checking if your system has it installed.
The lecture finally suggests different ways of handling the data if .bzip2 is not installed on your system.
The lecture introduces you to loading and parsing data from an index.json file.
You learn how to transform this data into a list on a webpage, extracting details like city, country, and flag.
With this information, you construct hyperlinked cities that lead to new PHP files where air quality calculations specific to each city are performed.
In this lecture, you learn how to develop the city.php file for your project by creating a basic structure and utilizing PHP to load your functions and design files.
The goal is to aggregate data to develop statistics and prevent potential error messages.
You also create code for error handling and control how error messages are displayed.
The lecture covers accessing parameter values from the URL and restructuring code to reduce nesting for easier readability.
In this lecture, you actively learn how to aggregate a large quantity of data, specifically focusing on PM 2.5 air quality readings.
You learn how to isolate relevant data, group it by date, and calculate the average value by using a for-loop to extract and manipulate the data into an accessible and readable form.
By the end of the lecture, you're able to generate an air-quality index for different cities, using PHP to calculate the average fine dust particle concentration for each month.
In this lecture, you learn how to handle faults and errors in data when building a stats array for air quality measurement data.
You use conditions to skip or include data based on its validity and specific parameters (PM 2.5 and PM 10).
You also learn how to create a nested array structure to collect different parameter measurements simultaneously.
Finally, you adapt your view code to display data based on your modified array structure including a table header and columns for each parameter.
In this lecture, you learn to refine the output of the app prototype worked on previously.
Key features include truncating and rounding off floating point numbers to two decimal places, and adding labels (units) for the measurements by extracting them directly from the data.
The lecture concludes with steps to display the city's name and flag written in the PHP code.
In this lecture, you learn how to implement an interactive visual chart using the open source JavaScript library, Chart.js, to your PHP project.
You are taught that PHP is run on the server side, while JavaScript runs in the browser.
The lecture walks you through the process of getting JavaScript data into PHP, using scripts to run a chart and demonstrating chart.js to create a line chart with custom inputs.
In this lecture, you learn how to create a script using PHP and JavaScript to plot available datasets for air quality indices such as PM 2.5 and PM 10.
You learn how to generate the correct code, provide the accurate labels and data, prepare the graph, and output data in JavaScript code.
In this lecture, you learn to handle missing data points in PHP and JavaScript, particularly for accurate average calculations in arrays with zero elements.
You discover how to use conditional statements to add zeros and prevent errors in computation, and to convert JavaScript nested arrays into PHP for JSON encoding.
This approach improves your flexibility in displaying data in graphs, ensuring meaningful and error-free visual representations.
*** Learn the modern way of writing PHP *** with 30 interactive exercises ***
Are you looking for an interactive, step-by-step program to master modern PHP and kickstart your career as a web developer in 2024? Then read on.
Many say that PHP is dead. But the truth is, PHP still powers 75% of online web applications today. This means that if you're looking to get a job as a web developer, or start a lucrative freelance career, you will encounter PHP.
The problem is, many courses focus on an old way of writing PHP, which is becoming outdated in the market. Following these programs will just make you frustrated because the code won't scale and will be difficult to maintain. You won't learn the required practices needed to build big-scale web applications, and therefore will never be able to kickstart a fulfilling career as a PHP developer.
This program aims to change that.
I designed this course to help you master PHP, step by step from beginner to pro, but in a way how it's written nowadays. We'll focus on mastering the concepts that can get you from 0 to building a simple content management system (CMS) with your own framework.
We will start with simple PHP code, but step by step, we'll introduce additional, concepts that turn PHP into a modern, powerful language: Object oriented programming, namespaces, autoloading, PSR-4, inheritance, PDO, MVC framework - just to name a few.
Also, you will learn about best-practices that help you prevent security attacks. You will learn how to prevent cross-site-scripting (XSS) attacks, SQL injections, privilege escalation attacks and even more. Being aware and being able to mitigate those risks is essential if you want to become a sought-after freelancer or an in-demand senior developer that companies can rely on.
And mind you, this course isn't just be theoretical. The chapters are packed with practical examples, engaging quizzes, and real-world scenarios that will make this experience fun and engaging. Plus, at the end of the course, you will also have built several projects you can showcase and use in your portfolio!
Last but not least, you will also learn the 'why' behind PHP - so that you feel confident to go out there and apply this knowledge to real-life projects.
So, after this course you will also be able to master various development styles. This course covers it all:
From simple PHP scripts for smaller projects
Over object oriented scripts for medium-sized projects
Up to MVC-Frameworks for large-scale projects
This allows you to develop professionally and know when you should use which style.
Some things you will learn:
PHP basics
How to run file uploads
How a web server works
How to access a database and write a guestbook
How to embed PHP in HTML
Functions, arrays, strings, if conditions,...
Control a database (MySQL / phpmyadmin)
How to create simple websites with PHP scripts
How to create an image gallery with upload functionality
How to write a CMS with object orientation & MVC patterns
Cookies & Sessions: Create a login system (and a cookie notice)
Learn how to keep track of complex projects with advanced PHP features (namespaces, autoloading, PSR-4, MVC patterns, container patterns, inheritance, ...)
The german version of this course is already the most popular PHP course on the German market here on Udemy. With this enhanced, english version, I'm opening this knowledge to the international market.
Enroll now and get your foot in the exciting world of web development!