Home » Articles by: Brad Morton

PHP in_array Function: Check Array Values Exist

PHP in_array Function

The PHP in_array() function allows you to check for the presence of a value in an array, and take an option based on this result. Syntax in_array ( $needle , $haystack [, $strict = FALSE ] ) Note That: $needle can be a variable of any type (string, number, date, etc) $haystack should be an array (see here, here, and here for more about arrays) $strict is optional, and will ensure that the type of values is also compared when checking whether $needle is present If $strict is FALSE (the default behavior), the number … Read more

Categories PHP

Home » Articles by: Brad Morton

Using the PHP Array ‘implode’ Function, with Examples

php implode function

We’ve previously covered the explode() function in PHP – now it’s time for implode()! This tutorial will teach you how to merge values from an array into a single string using the PHP implode() function. Processing data for presentation to the end-user is one of the common PHP tasks. PHP is frequently used on Linux to display database query results to the user. If some of those values are stored in an array, you may want to merge them into a single string for ease of display or brevity … Read more

Categories PHP

Home » Articles by: Brad Morton

PHP strpos Function: Check if a String Contains Another String

php strpos function

The PHP strpos() function checks whether a string is contained within another string – for example checking whether a certain word appears in a sentence, and what position it appears in.  It is a great companion to the PHP substr() and str_replace() functions for processing text data. Syntax strpos ( $haystack , $needle [, $offset = 0 ] ) Note that: $haystack is the string (text or series of characters) we want to search within $needle is the string search term we are looking for $offset Is optional … Read more

Categories PHP

Home » Articles by: Brad Morton

PHP ‘str_replace’ Function: Find and Replace Text

php str_replace function

The PHP str_replace() function replaces words or sections (known as substrings) in a string with other words or sentences, allowing you to modify or reformat text values (find and replace text). Syntax str_replace ( $search , $replace , $subject [, &$count ] ) Note that: $search is the string value being searched for – it can even be an array of strings if you wish to search for multiple values $replace is the value you wish to replace the $search value with – it can also be an array if … Read more

Categories PHP

Home » Articles by: Brad Morton

Using the PHP ‘explode’ Function (With Examples)

php explode function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP explode function is vital for processing user input. It takes a string (a series of characters) and splits it up into smaller strings by a given delimiter to specify the boundary of where the splits should occur. Syntax explode ( $delimiter , $string [, $limit ] ) Note that: $delimiter … Read more

Categories PHP

Home » Articles by: Brad Morton

Using the PHP ‘substr’ Function (With Examples)

Using the PHP 'substr' Function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP substr function takes a string (a series of characters) and returns only the specified portion of it. Syntax substr ( $string , $start [, $length ] ) Note that: The function returns either the specified portion of the given $string (even if it’s empty) as a new string … Read more

Categories PHP

Home » Articles by: Brad Morton

How to Install Ubuntu MATE 2020.10 on a Raspberry Pi (With Screenshots)

How to Install Ubuntu MATE 2020.10 on a Raspberry Pi

Ubuntu is (arguably) the most popular Linux distribution. Ubuntu MATE is a great, performance-conscious, lightweight Ubuntu-based distribution that is perfect for low-cost platforms like the Raspberry Pi where you may want to forgo some of the bells and whistles for better performance. If you’re just getting started learning Linux and programming you may not want to risk trying things out on your day-to-day computer (you might be worried about breaking it for work or school), a Raspberry Pi is a great way to experiment with … Read more

Home » Articles by: Brad Morton

Python Find in List: Check if an Element is Present

python find in list

Python offers several different types of arrays for storing data. Lists are arrays which allow you to store items. These list items can be altered, and are stored in a specific order. There are several methods you should consider for searching a list in Python– searching for a specific value match, or searching for list items that match a certain condition or set of conditions. You can also remove items from a list in Python. Checking if a List Contains an Item Using the ‘in’ … Read more

Home » Articles by: Brad Morton

Concatenating (Joining) Strings in Python

string concatenation python

Let’s look at two ways you can concatenate (which is a fancy word for join or merge) two or more strings in Python. It’s also worth checking out our article on converting integers to strings in Python. A Note On Immutable Strings Strings in Python are immutable and cannot be changed once defined. This means that whenever you join two strings, a new string is created (ie. the original is not modified!). This has both performance side effects and affects how you should structure your code: … Read more

Home » Articles by: Brad Morton

Escape Characters in Python, With Examples

Escape Characters in Python

Every programming language has special characters that trigger certain behaviors in your code – and Python is no exception. These characters cannot be used in strings (as they are reserved for use in your code) – and must be “escaped” to tell the computer that the character should just be treated as a regular piece of text rather than something that needs to be considered while the code is being executed. If you want to be able to leave yourself notes in your code, check … Read more