Truncating Strings in PHP

Context: Often, we want to truncate a long string to a particular length and replace truncated characters with a custom Placeholder. Solution: We can us substr() function to truncate string to specified length and append custom placeholder to the truncated string. The user defined function turncatedString() accepts, three arguments: the String to truncate, the length to which it must be […]

How to reverse string in PHP

Context: YOu want to reverse a string. Solution: We can use the strrev() functions How to reverse string in PHP is extremely simple, this” give it is string, and strrev [] gives it back to you in reverse” task. but despite the fact that it’s nothing to write home about, strrev [] is often used to perform some advanced tasks.

Checking for Empty String Values

Context: You want to check if a string value contains valid characters Solutions: We can use the combination of isset() and trim() functions. We used this often working with form data to see if a required field contains valid data or not. The basic technique is simple, use isset() to verify that string variable exists and then use trim() function […]

Controlling String Case

Context: ¬†You want to force a string to upper or lowercase in PHP. Solution: Controlling String Case in PHP, not that difficult, Use strtoupper() or strtolower() functions: Example: When it comes to altering the case of a string, PHP makes it easy with four built-in functions. Two of them are illustrated in example above. strtoupper() converts string into upper case […]