Found 1060 Articles for PHP

PHP – Match regular expression using mb_ereg_match()

Urmila Samariya
Updated on 11-Oct-2021 12:53:09

458 Views

In PHP, mb_ereg_match() function is used for matching a given string with a regular expression pattern. This function only matches the string from the beginning of the string and it is not necessary that it will match the string till the end. This function will return true or 1 if a match is found, else it will return False or 0.Syntaxbool mb_ereg_match(str $pattern, str $string, str $options)ParametersIt accepts the following three parameters −$pattern − This parameter is used for the regular expression.$string − This parameter is being evaluated.$options − It is used for the search.Return Valuesmb_ereg_match() returns true or 1 ... Read More

PHP – Get aliases of a known encoding type using mb_encoding_aliases()

Urmila Samariya
Updated on 11-Oct-2021 12:49:47

193 Views

In PHP, mb_encoding_aliases() is used to get the aliases of a known encoding type. This function is supported in PHP 5 or higher version.Syntaxarray mb_encoding_aliases(str $encoding)ParametersIt accepts only one parameter, $encoding, which is the encoding type checked for aliases.Return ValuesIt returns a numerically indexed array of encoding aliases on success or it returns False on failure.Errors/ExceptionsIf the encoding is not known, then it gives an E_WARNING level error.Example 1OutputArray ( [0] => ANSI_X3.4-1968 [1] => iso-ir-6 [2] => ANSI_X3.4-1986 [3] => ISO_646.irv:1991 [4] => US-ASCII ... Read More

PHP – Encode string for MIME header using mb_encode_mimeheader()

Urmila Samariya
Updated on 11-Oct-2021 12:43:16

568 Views

In PHP, mb_encode_mimeheader() function is used to encode a string for MIME (Multipurpose Internet Mail Extensions) header. It encodes a given string by the MIME header encoding scheme.Syntaxstring mb_encode_mimeheader(str $string, str $charset, str $transfer_encoding, str $newLine, int $indent)ParametersThe mb_encode_mimeheader() function accepts five parameters −$string − This parameter is used to encode the string. Its encoding should be the same as mb_internal_encoding()$charset − This parameter specifies the character set name in which the string is represented.$transfer_encoding − This parameter specifies the scheme of MIME encoding. It should be base64 (B) or Quoted-printable (Q). If not given, then it falls back to ... Read More

PHP – How to detect character encoding using mb_detect_encoding()

Urmila Samariya
Updated on 11-Oct-2021 12:19:32

7K+ Views

In PHP, mb_detect_encoding() is used to detect the character encoding. It can detect the character encoding for a string from an ordered list of candidates. This function is supported in PHP 4.0.6 or higher version.mb_detect_encoding() is useful with multibyte encoding, where not all sequences of bytes form a valid string. If the input string contains such type of a sequence, then that encoding will be rejected, and it will check for the next encoding.Syntaxstring mb_detect_encoding(str $string, str $encoding, bool $strcit)Automatic detection of character encoding is not entirely reliable without some additional information. We can say that character encoding detection is ... Read More

PHP – How to get the substitution character using mb_substitute_character()?

Urmila Samariya
Updated on 23-Aug-2021 08:34:59

295 Views

In PHP, we can use the function mb_substitute_character() to get the substitution character. This function specifies the substitution character when the input character encoding is not valid or the character code does not exist in the output character encoding.Note: The invalid characters may be substituted with no output, string, or int value (Unicode character code value).Syntaxstring mb_substitute_character($char)ParametersThis function accepts only one parameter, $char.$char− It specifies the Unicode value as an integer or the strings given below:"none"− It will return no output."long"− It is used for the output character code value. For example, "U+3000, JIS+7E7E""entity"− it is used to return the output ... Read More

PHP – Get the string length using mb_strlen()

Urmila Samariya
Updated on 23-Aug-2021 08:34:29

2K+ Views

In PHP, multibyte string length (mb_strlen) function is used to get the total string length of a specified string. This function is supported in PHP 4.6.0 or higher versions.Syntaxint mb_strlen(str $string, str $encoding)Parametersmb_strlen() accepts two parameters: $string and $encoding.$string− It is used to check the string length$encoding− This parameter is used for character encoding. If it is omitted or null, then the internal character encoding value will be used.Return Valuesmb_strlen() returns the number of characters present in the given string. One is counted as a multi-byte character.Errors/ExceptionsIf the encoding is not known, then it will generate the level E_warning.Example Live DemoOutputTotal ... Read More

PHP – How to set the character encoding detection order using mb_detect_order()?

Urmila Samariya
Updated on 23-Aug-2021 08:33:52

234 Views

The mb_detect_order() function in PHP can be used to set/get the character encoding detection in an order. This function is supported in PHP 4.2.0 or higher versions.Syntaxarray|bool mb_detect_order(str $encoding)Parametersmb_detect_order() accepts only one parameter $encoding with string, array and bool.$encoding− This encoding parameter is an array or comma-separated list of character encoding. If it is omitted or null, then it returns the current character encoding detection order as an array.Return ValuesWhen setting the encoding detection order, it returns True on success or it returns False on failure.Example Live DemoOutputASCII, JIS, EUC-JPRead More

PHP – Make a lower case string using mb_strtolower()

Urmila Samariya
Updated on 23-Aug-2021 08:33:23

530 Views

In PHP, we can use the function mb_strtolower() to change a given string into lower case. It returns strings with all alphabetic characters converted to lowercase characters.Syntaxstring mb_strtolower(str $string, str $encoding)Parametersmb_strtolower() accepts two parameters: $string and $encoding.$string− The string being lowercased, returns strings with all alphabetic characters converted to lowercase characters.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return Valuesstring with all alphabetic characters converted to lowercase.Example Live DemoOutputIt will conver all the characters in the given string to its lower case.hello world! welcome to online tutorialsRead More

PHP – Make an upper case string using mb_strtoupper()

Urmila Samariya
Updated on 23-Aug-2021 08:32:07

318 Views

In PHP, mb_strtoupper() is an inbuilt function that is used to change a given string to upper case.Syntaxstring mb_strtoupper(str $string, str $encoding)Parametersmb_strtoupper() accepts two parameters: $string and $encoding.$string− The string being uppercased.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return Valuesstring with all alphabetic characters converted to uppercase.Example Live DemoOutputIt will convert the given string to upper case.HELLO WORLD!, WELCOME TO ONLINE TUTORIALS

PHP – How to count the number of substring using mb_substr_count()?

Urmila Samariya
Updated on 23-Aug-2021 08:30:29

184 Views

In PHP, we can use the function mb_substr_count() to count the total number of substrings in a given string.Syntaxint mb_substr_count(str $haystack, str $needle, str $encoding)Parametersmb_substr_count() accepts three parameters: $haystack, $needle and $encoding.$haystack− This parameter will check the string.$needle− This parameter will be used to tell that the substring is found from the given total string.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return ValuesThis will return the number of times the needle substring occurs in the haystack string.Example Live DemoOutput2Read More

Advertisements