PHP Code Snippets Working With Strings

PHP Working With Strings

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.

PHP Code Snippets Working With Arrays

PHP Working With Arrays

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.

PHP Code Snippets JSON

PHP Working With JSON

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.

PHP Code Snippets ReCaptcha V3 Implementation

ReCaptcha V3 Implementation

In this post, we’ll learn how to implement reCAPTCHA on a website. Recaptcha is used to confirm that the user interaction on your site was made by a human and not by some script. For example, if you have a contact form on your website you would want to implement some human verification to prevent getting spammed by bots.

PHP Code Snippets String Sanitization

PHP String Sanitization

In this code snippet, we’ll learn how to perform string sanitization in PHP. An attacker might try to inject some malicious code into your backend. As a developer, you can prevent that by filtering/sanitizing and validating your data before working with it.

Code Snippets Uploading Files

File Uploads With JS And C# Azure Functions

In this code snippet, we’ll learn how to upload files with Javascript. We will use the input HTML element and set its type to “file”. Then javascript can be used to retrieve the selected file from the input element and send it to the backend. You can use whatever you want for your backend: nodejs, PHP,  Java or in this case I will use a C# Azure function.

Code Snippets Downloads

Javascript Downloads

In this code snippet, we’ll learn how to perform downloads with Javascript. File downloads can be programmatically started with javascript by creating a temporary link element that points to your file. Then you add it to the DOM and call its click function to initiate the download. Finally, you can remove the link.

Advertisment ad adsense adlogger