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.
In this code snippet, we’ll learn how to work with strings in PHP. More specifically we’ll learn how to concatenate(join) strings, trim white spaces, make a string lower or upper case, get its length, check if it contains a substring and get its position, replace a substring, remove tags and slashes, split a string into an array on a specific character and join a string array back into a string.
In this code snippet, we’ll learn how to work with arrays in PHP. More specifically we’ll learn how to merge arrays, add/remove elements, reverse the array, remove duplicates, search the array, find its length, make associative arrays and get their keys. Associative arrays are use strings for indexes instead of numbers.
In this code snippet, we’ll learn how to work with JSON in PHP. You can use json_encode() to serialize and json_decode() to deserialize JSON. json_decode() also takes a second parameter(true/false) where you can specify if you want the JSON to deserialized to an associative array or to an object. In this post, you can see a practical example of JSON serialization/deserialization.
In this code snippet, we’ll see how to send HTTP requests with curl in PHP. Curl can be used to make HTTP request from the backend in PHP. In this desmonstration we’ll make a POST request to a test API.