How to use preg_split() function to split strings based on regular expressions and how to use preg_grep() function to search through an entire array of strings looking for text that matches a regular expression.
Author: BrainBell
Learn how to use preg_replace_callback_array() and preg_replace_callback() functions to perform a regular expression search and replace using callbacks.
Search and replace with preg_replace()
Learn how to use the preg_replace() function to replace all occurrences of a pattern (regular expression) with replacement and get the modified result.
The preg_match() function searches a string for a specific pattern, it finds only the first match. On the other hand, the preg_match_all() function finds all matches in the string.
Regular Expressions
A regular expression or regex is used for searching, editing, extracting and manipulating data. Using regular expressions (regex) you can verify if a specific string matches a given text pattern or to find out a set of characters from a sentence or large batch of characters.
Convert a delimited string into an array
How to parse a CSV, tab, space, or any other single-byte character delimited string into an array using the str_getcsv() function.
Split, tokenize, and iterate a string
In this tutorial, we’ll discuss the str_split() and mb_str_split() functions to split a string into an array based on a specified length, strtok() function to split a string into smaller strings (tokens), and chunk_split() to split a string into smaller chunks.
Count Characters and Words
Get byte values of all characters in a string and find how many times the byte-value occurred, how many times a character appears in a given string, receives unique characters from a string, etc. with count_chars() function. Also, count words in a string, convert a string into an array by words, get the frequency of all words in a string, find the position of each word in a string, etc. with str_word_count() function.
Repeat and Shuffle a String
How to use str_repeat() function to repeat a string a given number of times. You’ll also learn to shuffle a string to create a password generator.
All characters, even if they are not available on your keyboard, have a character code. PHP offers four functions to deal with these characters code: ord() and chr() to deal with single-byte characters; mb_ord and mb_chr() to deal with multi-byte characters. The chr() and mb_chr() convert the numeric value into the corresponding character; ord() and mb_ord() returns the numeric value for characters.