In this code snippet, we’ll make a global exception handler in PHP. A global exception handler is used to catch any unhandled exception that might bubble up in your code. This way you can log the exception and let the user know there was an error instead of the program just crashing.
In this code snippet, we’ll make a REST API with the Slim framework in PHP. Slim is a framework that enables you to easily and quickly build REST APIs in PHP. I will show you how to make a POST and GET endpoint. Other types of requests follow the same logic. Official dodumentation here. We will also enable CORS so you can call the API from the browser.
In this code snippet, we’ll take a look at objects and basic of object oriented programming in PHP. I will just show how to make and use classes, interfaces, properties, … in PHP. I won’t go into OOP too much as I already did some other posts about that.
In this code snippet, we’ll learn how to perform file downloads in PHP with the file_get_contents() function. The file_get_contents() function gets/downloads a file(locally or from the web) as a string. We can then modify the string and save it with file_put_contents().
In this code snippet, we’ll learn how to force file downloads in PHP.
In this code snippet, we’ll learn how to perform data validation in PHP. Data validation is used to make sure the input data is present and in the correct format for further processing. This can be performed either on the front or backend.
In this code snippet, we’ll learn about the date() function in PHP. The date() function takes in a string that specifies the date/time format and gives you the result.
In this code snippet, we’ll learn about the dirname() function in PHP. The dirname() function takes in a path string and gives you the parent directory of it. A second parameter can be added where you can specify how many levels up you want to go.
In this code snippet, we’ll learn how to get HTTP request variables in PHP. When an HTTP request is made to the PHP backend the data associated with the request(POST body, GET url parameters, cookies, …) will get stored as superglobal variables available from everywhere in the code. Here we’ll see how to access some of these values.
In this code snippet, we’ll learn how to pass and work with variables by reference in PHP. Variables can be passed either by value or by reference. Usually, we do it by value meaning you pass just the value and not the variable itself. So, any changes made locally inside the function scope won’t be seen outside of the function scope.