JavaScript

Adding Zeros to the front of a number in JavaScript.

To format a number to always have six characters, including leading zeros if necessary, you can use JavaScript’s padStart method. This method pads the current string with another string (repeated, if needed) until the resulting string reaches the desired length. Here’s a simple example of how to do this: Explanation: You can use this function […]

Loading

Read More
PHP

How to add a BCC to PHP mail() command.

To add BCC (Blind Carbon Copy) recipients when sending mail in PHP, you can modify the headers to include BCC recipients. Here’s how you can do it: Example using PHP mail() function: Explanation: This will send the email to the primary recipient and also BCC it to bcc1@example.com and bcc2@example.com. Considerations:

Loading

Read More
PHP

How to use Māori macrons in your PHP 8.3 code.

To convert UTF-8 characters with macrons (e.g., Māori macrons like “ā”, “ē”, etc.) into their corresponding HTML entity codes in PHP, you can use the mb_encode_numericentity() function from the mbstring extension. Here’s an example of how to achieve this: Example Code: Explanation: Example Input/Output: Notes: This approach will correctly convert the UTF-8 macron characters to […]

Loading

Read More
Linux

What are Load Averages?

Load averages represent the average number of processes that are either: They give a snapshot of how much work your system has been doing over time. Linux usually reports three numbers for load average, which represent the load over different periods: For example, when you run the uptime or top command, you might see something […]

Loading

Read More
Linux

[SOLVED] The following signatures were invalid: EXPKEYSIG B188E2B695BD4743 DEB.SURY.ORG Automatic Signing Key

Here is the solution if you’ve got the following error message when updating package lists on Debian (apt-get update): The following signatures were invalid: EXPKEYSIG B188E2B695BD4743 DEB.SURY.ORG Automatic Signing Key The sury.org Debian package repository has changed its package signing key. To fix the error, just download the new key: Finally, run package update again: […]

Loading

Read More
JavaScript

Change the Text of a Div Element using JavaScript

Use the textContent property to change the text of a div element, e.g. div.textContent = ‘Replacement text’. The textContent property will set the text of the div to the provided string, replacing any of the existing content. Here is the HTML for the examples in this article. index.html And here is the related JavaScript code. index.js We used the textContent property on the div to change its text […]

Loading

Read More
PHP

Validate Password Strength using PHP

When the user provides their account password, it is always recommended to validate the input. Password strength validation is very useful to check whether the password is strong. A strong password makes the user’s account secure and helps to prevent account hacking. Using Regex (Regular Expression), you can easily validate the password strength in PHP. […]

Loading

Read More
Linux

Backup a website using bash script.

I needed to complete a routine backup of my development websites on my home server. This was pretty easily completed by daily by a bash script. Here is a simple script that backs up the database and all the files. For the example below I’m using Maria DB 10.5 and my project files are located […]

Loading

Read More
PHP

An Introduction to Classes and Objects in PHP 8+

What is OOP? Object-oriented programming (OOP) is a computer programming model that organizes software design around objects rather than single functions. An object can be defined as a data field that has unique attributes and behavior. A class is a container for objects to be manipulated using methods (internal functions). OOP Let’s assume we have […]

Loading

Read More