w3resource

Installing and configuring PHP String Functions

Requirements

PHP String functions do not require any external library files.

Installation

Since PHP String functions are part of the PHP core, they don't require any installation.

Runtime Configuration

You don't need to add any directive in php.ini for running PHP String functions.

Resource Types

PHP String functions have no defined resource types defined.

Predefined constants

In the following table, we have given a list of constants which are part of the PHP core.

String constants
Constant's Name Type
CRYPT_SALT_LENGTH Integer
CRYPT_STD_DES Integer
CRYPT_EXT_DES Integer
CRYPT_MD5 Integer
CRYPT_BLOWFISH Integer
HTML_SPECIALCHARS Integer
HTML_ENTITIES Integer
ENT_COMPAT Integer
ENT_QUOTES Integer
ENT_NOQUOTES Integer
CHAR_MAX Integer
LC_CTYPE Integer
LC_NUMERIC Integer
LC_TIME Integer
LC_COLLATE Integer
LC_MONETARY Integer
LC_ALL Integer
LC_MESSAGES Integer
STR_PAD_LEFT Integer
STR_PAD_RIGHT Integer
STR_PAD_BOTH Integer

See also

PHP Function Reference

Previous: tanh
Next: addcslashes



PHP: Tips of the Day

PHP will generally correctly guess the data type you intend to use from the context it's used in, however sometimes it is useful to manually force a type. This can be accomplished by prefixing the declaration with the name of the required type in parenthesis:

Example:

$bool = true;
var_dump($bool); // bool(true)
$int = (int) true;
var_dump($int); // int(1)
$string = (string) true;
var_dump($string); // string(1) "1"
$string = (string) false;
var_dump($string); // string(0) ""
$float = (float) true;
var_dump($float); // float(1)
$array = ['x' => 'y'];
var_dump((object) $array); // object(stdClass)#1 (1) { ["x"]=> string(1) "y" }
$object = new stdClass();
$object->x = 'y';
var_dump((array) $object); // array(1) { ["x"]=> string(1) "y" }
$string = "asdf";
var_dump((unset)$string); // NULL

But be careful: not all type casts work as one might expect:

// below 3 statements hold for 32-bits systems (PHP_INT_MAX=2147483647)
// an integer value bigger than PHP_INT_MAX is automatically converted to float:
var_dump( 999888777666 ); // float(999888777666)
// forcing to (int) gives overflow:
var_dump((int) 999888777666 ); // int(-838602302)
// but in a string it just returns PHP_INT_MAX
var_dump((int) "999888777666"); // int(2147483647)
var_dump((bool) []); // bool(false) (empty array)
var_dump((bool) [false]); // bool(true) (non-empty array)