Home » Programming » PHP

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 » Programming » PHP

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 » Programming » PHP

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 » Programming » PHP

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 » Programming » PHP

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 » Programming » PHP

How to use ‘try/catch’ in PHP (with Examples)

'try/catch' in PHP

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. When writing PHP code, you’ll sometimes want to perform a certain action when an error is encountered (rather than just sending the user an error message and halting code execution). This is exactly what try/catch is used for in PHP. Syntax try { // Code to attempt } catch (Exception $e) { … Read more

Categories PHP