Earlier we presented the basic method for outputting text with echo and print, and the functions print_r( ) and var_dump( ), which can determine the contents of variables during debugging. PHP provides several other functions that allow more complex and controlled formatting of strings.
Author: BrainBell
Convert HTML Entities and Special Characters
Learn how to encode or decode all or special HTML characters within a string.
Converting Strings into HTML
A commonly used web attack is called Cross-Site Scripting (XSS). For example, a user enters some malicious data, such as JavaScript code, into a web form; the web page then at some point outputs this information verbatim, without proper escaping. Standard examples for this are your blog’s comments section or discussion forms.
Learn how comparison (a string comparison) actually made and how to perform the natural order comparison with stratum() and strnatcasecmp() functions. The natural order comparison treats the string’s numeric parts separately, these functions implement an algorithm that compares alphanumeric strings in the way a human being would.
Comparing Strings
PHP offers four functions for comparing strings: strcmp(), strcasecmp(), strncmp(), and strcasencmp(). These functions return a positive value when the string passed as the first parameter is greater than the second parameter, and a negative value when it is smaller. If both strings are equal then 0 is returned.
How to change the string case?
In this tutorial, you’ll learn how to change the case of a string. For example, capitalize the first character of a string or word or change the case of the whole string to upper or lower case. This tutorial also explains how to alter the case of Multibyte characters.
aray_map() and array_walk()
How to modify all array elements, or nested array elements using array_map() and array_walk() functions. What is the difference between array_walk() and array_map() functions.
array_filter(): Filtering Arrays
The array_filter() function filters the elements of an array by applying a callback function to each element to decide whether it appears in the output array. The callback function returns true upon success and false otherwise.
Finding values and keys in arrays
Check if a value or key exists in the array with in_array and array_key_exists functions respectively. Search the array by value and get first or all corresponding keys from the array with array_search and array_keys functions.
Shuffle Array and Get Random Elements
If you want to randomize the order of elements in the array use the shuffle() function. Or use array_rand() function to grab one or more random elements out of an array.