Code Snippets Using DomDocument To Work With HTML

PHP Using DomDocument To Work With HTML

In this code snippet, we’ll see how to work with HTML using DomDocument in PHP. If you need to change HTML in code or extract some data from it(web scraping) you can use the DomDocuemnt class to help you with that. You simply create a new instance of it and load the HTML and then you can use its functions to access the DOM.

Code Snippets Global Exception Handler

PHP Global Exception Handler

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.

PHP Code Snippets APIs With The Slim Framework

PHP APIs With The Slim Framework

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.

PHP Code Snippets OOP and Objects

PHP Objects And OOP

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.

PHP Code Snippets Data Validation

PHP Data Validation

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.

Code Snippets Dirname

PHP dirname() Function

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.

Code Snippets Request Variables

PHP Request Variables

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.

Advertisment ad adsense adlogger