Found 1046 Articles for PHP

PHP – How to cut out part of a string using iconv_substr()?

Urmila Samariya
Updated on 23-Aug-2021 08:24:27

187 Views

In PHP, the iconv_substr() function is used to cut a portion of a specified string by the offset and length parameters. Suppose we have a string "helloWorld" and we want to cut and show only the string (llowo), then we will select it by using numbers from 2 to 5.Syntaxstring iconv_substr(str $string, int $offset, int $length, str $encoding)Parametersiconv_substr() accepts four parameters: $string, $offset, $length and $encoding.$string− The $string parameter specifies the original string.$offset− If the $offset parameter is non-negative, then the iconv_substr() function cuts the selected portion of the string from beginning at offset character, counting from zero. And if ... Read More

PHP – Find the last occurrence of a needle within a haystack using the iconv_strrpos() function

Urmila Samariya
Updated on 23-Aug-2021 08:22:54

186 Views

In PHP, the iconv_strrpos() function is used to findsthe last occurrence of a needle within a haystack. Or, we can say that the iconv_strrpos() function returns the last character number from the haystack.Syntaxstring iconv_strrpos(string $haystack, str $needle, str $encoding)Parametersiconv_strrpos() accepts three parameters: $haystack, $needle and $encoding.$haystack− It denotes the whole string.$needle− The $needle parameter is used to search the substring from the given whole string.$encoding− if the $encoding parameter is absent or null, then the string will assume that it may be encoded in iconv.internal_encoding.Return Valuesiconv_strpos() returns the numeric position of the given first occurrence of the needle from the ... Read More

PHP – iconv_strpos() function – Find the position of the first occurrence of a needle in a haystack

Urmila Samariya
Updated on 23-Aug-2021 08:21:44

339 Views

In PHP, the iconv_strpos() function is used to read the first character from a given string. It finds the position of the first occurrence of a character in a string. It is an inbuilt function in PHP.Syntaxstring iconv_strpos(string $haystack, string $needle, int $offset, string $encoding)Note: strpos(), the return value of iconv_strpos() is the number of characters that appear before the needle, rather than the offset in bytes to the position where the needle has been found. The characters are counted based on the specified character set encoding.Parametersiconv_strpos() function accepts four different parameters− $haystack, $needle, $offset and $encoding.$haystack− It denotes the ... Read More

PHP – How to return the character count of a string using iconv_strlen()?

Urmila Samariya
Updated on 23-Aug-2021 08:20:50

256 Views

In PHP, the iconv_strlen() function is used to return the character count of a given string. This is an inbuilt function in PHP that is first used in PHP 5 version. Encoding is nullable from PHP 8.0.Syntaxstring iconv_strlen(str $string, str $encoding)ParametersThis PHP function accepts two parameters: $string and $encoding.$string− The $string parameter is used for the input string.$encoding− If the $encoding parameter is absent or it is null, then the string is assumed to be encoded in iconv.internal_encoding.Return ValuesThe iconv_strlen() function returns the list of characters count which is present in the given string, or it returns False if an error ... Read More

PHP – Set the current setting for character encoding conversion using iconv_set_encoding() function

Urmila Samariya
Updated on 21-Aug-2021 07:51:05

185 Views

In PHP, the iconv_set_encoding() function is used to set the current character encoding conversion. It is an inbuilt function in PHP that changes the value of the internal configuration variable specified by type to encoding.Syntaxstring iconv_set_encoding(string $type, string $encoding)Parametersiconv_set_encoding() takes two parameters − $type and $encoding.$type − The $type parameter can be input_encoding, output_encoding or internal_encoding.$encoding − The $encoding parameter is used for the character set.Return Valuesiconv_set_encoding() returns True on success and False on failure.Example Live Demo     Outputarray(3) {    ["input_encoding"]=>    string(5) "UTF-8"    ["output_encoding"]=>    string(5) "UTF-8"    ["internal_encoding"]=>    string(5) "UTF-8" }Read More

PHP – Compose a MIME header field using iconv_mime_encode() function

Urmila Samariya
Updated on 21-Aug-2021 15:10:01

218 Views

In PHP, iconv_mime_encode() function is used to composes a MIME header field. This is an inbuilt PHP function.Syntaxstring iconv_mime_encode(string $field_name, string $field_value, array $options=[])The iconv_mime_encode() function is used to compose and return a string that represents a valid MIME header field, which looks like -Subject: =ISO-8859-1?Q?Pr=FCfung_f=FFCr?= Entwerfen von einer MIME kopfzeileNote− In the above example, Subject - is the field name, and the portion that begins with "=ISO-8859-1?..." is the field value.Parametersiconv_mime_encode() accepts three different parameters − $field_name, $field_value and $options.$field_name − This parameter is used for the field name.$field_value − This parameter is used for the field value.$options − ... Read More

PHP – How to decode a MIME header field using iconv_mime_decode() function?

Urmila Samariya
Updated on 21-Aug-2021 07:46:06

304 Views

In PHP, iconv_mime_decode() function is used to decode a MIME header field. This is an inbuilt function in PHP that is used from the PHP 5 version.SyntaxString iconv_mime_decode(string $string, int $mode, string $encoding)ParametersThe iconv_mime_decode() accepts three different parameters− $string, $mode and $encoding. $string and $mode are mandatory parameters, but $encoding is optional.$string − The $string parameter is used for the encoded header. It is a string-type parameter.$mode − The $mode parameter determines the behavior in the event iconv_mime_decode() it encounters the malformed MIME header field. We can specify any combination of the below-given bitmasks.List of bitmasks acceptable to iconv_mime_decode_headers()ICONV_MIME_DECODE_STRICTICONV_MIME_DECODE_CONTINUE_ON_ERRORICONV_MIME_DECODE_STRICT − ... Read More

PHP – Decode multiple MIME header fields at once using iconv_mime_decode_headers()

Urmila Samariya
Updated on 21-Aug-2021 07:44:06

130 Views

In PHP, iconv_mime_decode_headers() function is used to decode multiple MIME header fields at once. It is an in-built function in PHP.Syntaxiconv_mime_decode_headers($str_headers, $int_mode, $str_encoding)ParameterThe iconv_mime_decode_headers() function accepts three different parameters− $headers, $mode and $encoding.$headers − The $header parameter is used for the encoded headers. It is a string type parameter.$mode − The $mode parameter determines the behavior in the event iconv_mime_decode_headers() encounters a deformed MIME header field. We can use any combination of the following bitmasks.List of bitmasks acceptable to iconv_mime_decode_headers()ICONV_MIME_DECODE_STRICTICONV_MIME_DECODE_CONTINUE_ON_ERRORICONV_MIME_DECODE_STRICT -  If the iconv_mime_decode_strict is set, the given header is decoded in full conformance but this option is disabled by ... Read More

PHP – Retrieve internal configuration variables of iconv extension using iconv_get_encoding() function

Urmila Samariya
Updated on 21-Aug-2021 07:41:51

124 Views

In PHP, the iconv_get_encoding() function is used to retrieve the internal configuration variables of iconv extension. This function is an inbuilt PHP function which is being used from PHP 4 version.Syntaxmixed iconv_get_encoding($type = "all")ParameterThe iconv_get_encoding() function is used only single parameter $type.$type − The values of the optional type parameter can beallinput_encodingoutput_encodinginternal_encodingReturn ValueThe iconv_get_encoding() function returns the current value of the internal configuration variable if successful or it returns False on failure. If the type is not present or set to all,  then iconv_get_encoding() returns an array that stores all these variables.Example 1 Live Demo     Outputarray(3) {    ["input_encoding"]=>   ... Read More

PHP – How to get the square root of an arbitrary precision number using bcsqrt() function?

Urmila Samariya
Updated on 21-Aug-2021 07:39:27

133 Views

In PHP, the bcsqrt() function is used to get the square root of an arbitrary precision number. It accepts the arbitrary precision number as a string and gives the square root of the number after scaling the result to the specified precision.Syntaxstring bcsqrt($num_string, $scale)ParametersThe bcsqrt() function accepts two different parameters: $num_string and $scale.$num_string − It represents the number whose square root to be evaluated. It is a string-type parameter.$scale − It indicates the number of digits that appear after the decimal point in the output.Return ValueThe bcsqrt() function returns the square root of the number as a string.Example 1OutputOutput without ... Read More

Advertisements