Functions to work with strings in PHP

If you were a cat, string functions would be the cat's meow, all puns intended.(*юмор) Besides being a large part of your PHP code, they provide much of the functionality to identify and alter your data into other formats, such as arrays.

sprintf(formatting,inputs,[, …inputs…])

Accepts multiple inputs to be used when specified in formatting

formatting – $string, specific formatting string, explained below

inputs – $scalar(s) to be formatted

Every time an input is expected to be used and evaluated as part of the formatted string, it is preceded by a percent sign (%), followed by the

specifiers/rules:

Note: All specifiers, excluding the type specifier, are optional.

A sign specifier. Placing a plus sign (+) forces negative AND

positive signs to be visible.

A padding specifier. The default is a space, and does not need to be specified. A zero (0) can be used as well without any secondary notation. If any other character is to be used, it should be preceded with a single quote (').

An alignment specifier. The default is right-justified (thus padding is placed on the left of the string). Placing a dash/ subtract (-) will set it to left-justified.

A width specifier. This integer determines the minimum length in characters the output should be. When combined with padding, the specified width minus the input's length determines the number of padded characters that will be added.

A precision specifier. A period (.) followed by an integer, sets the number of decimal places that should be output for a float. If used on a string, it sets a maximum character limit for the output.

implode() – Creates a string from array elements, using a joining string

explode() – Separate a string into an array using a specific delimiting string

chr() – Get the ASCII character represented by its byte-value

printf() – prints a formatted string results rather than simply returning them

sscanf() – Parses a string through a formatted string, reverse of sprintf()

addslashes() – Adds backslashes to make a string safe for database queries


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: