Found 35163 Articles for Programming

str_pad() function in PHP

Ankith Reddy
Updated on 24-Jun-2020 13:40:25

406 Views

The str_pad() function is used to pad a string to a new length. It returns the padded string.Syntaxstr_pad(str, len, pad_str, pad_type)Parametersstr − The string to padlen − The new string lengthpad_str − The string to use for paddingpad_type − The side to pad the string.The following are the possible values −STR_PAD_BOTH  − Pad to both sides of the string. If not an even number, the right side gets the extra paddingSTR_PAD_LEFT  − Pad to the left side of the stringSTR_PAD_RIGHT  − Pad to the right side of the string.ReturnThe str_pad() function returns the padded string.ExampleThe following is an example − Live ... Read More

str_ireplace() function in PHP

Samual Sam
Updated on 24-Jun-2020 13:40:48

110 Views

The str_ireplace() function is used to replace the characters with some other characters.Note − The function is case-insensitiveSyntaxstr_ireplace(find,replace,str,count)Parametersfind − The value to be searchedreplace − The value to replace the value in findstr − The string to be searchedcount − The number of replacementsReturnThe str_ireplace() function returns a string or array with the replaced values.The following is an example −Example Live DemoThe following is the output −OutputI am DavidLet us see another example −Example Live DemoThe following is the output −OutputArray (    [0] => one    [1] => two    [2] => four ) Number of Replacements = 1

str_getcsv() function in PHP

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

355 Views

The str_getcsv() function is used to parse a CSV string into array. It returns an array with CSV fields in it. Syntax str_getcsv(str, delimiter, enclosure, escape Parameters str − Parse the input string delimiter − Set the field delimiter enclosure −Set the field enclosure character escape − Set the escape character Return The str_getcsv() function returns an array with CSV fields in it. Example The following is an example to parse a CSV file into an array − Output The content of “new.csv” would be visible demo text

sprintf() function in PHP

karthikeya Boyini
Updated on 26-Dec-2019 07:52:05

546 Views

The sprintf() function is used to output a formatted string.Syntaxsprintf(format, arg1, arg2, arg++)Parametersformat − Specifies the string and how to format the variables in it.The following are the possible format values −%% - Returns a percent sign%b - Binary number%c - The character according to the ASCII value%d - Signed decimal number (negative, zero or positive)%e - Scientific notation using a lowercase (e.g. 1.2e+2)%E - Scientific notation using a uppercase (e.g. 1.2E+2)%u - Unsigned decimal number (equal to or greater than zero)%f - Floating-point number (local settings aware)%F - Floating-point number (not local settings aware)%g - shorter of %e and ... Read More

soundex() function in PHP

George John
Updated on 30-Jul-2019 22:30:23

100 Views

The soundex() function in PHP is used to calculate the soundex key of string. The key is a four character long alphanumeric string representing English pronunciation of a word. Syntax soundex() Parameters NA Return The soundex() function returns the soundex key as a string. Example The following is an example − Live Demo Output W425

similar_text() function in PHP

Samual Sam
Updated on 26-Dec-2019 07:50:53

95 Views

The similar_text() function is used to calculate the similarity between two strings.Syntaxsimilar_text(str1, str2, percent)Parametersstr1 − The first thing to be comparedstr2 − The second string to be comparedpercent − Specifies a variable name for storing the similarity in percent.ReturnThe similar_text() function returns the number of matching characters of two strings.ExampleThe following is an example − Live DemoOutputThe following is the output −Count of similar characters : 5ExampleLet us see another example that checks for two empty strings − Live DemoOutputThe following is the output −0

sha1() function in PHP

Chandu yadav
Updated on 24-Jun-2020 13:42:09

151 Views

The sha1() function in PHP is used to calculate the sha1 hash of a string. Let us first see what is SHA-1 −The US Secure Hash Algorithm 1 − "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a ... Read More

sha1_file() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 13:42:24

53 Views

The sha1_file() function is used to calculate the sha1 hash of a file.Syntaxsha1_file(file_name, raw)Parametersfile_name − Specify the fileraw − A boolean value that specifies hex or binary output format −TRUE - Raw 20 character binary formatFALSE - 40 character hex numberReturnThe sha1_file() function returns the SHA-1 hash on success, or FALSE on failure.ExampleThe following is an example −OutputThe following is the output −aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

setlocale() function in PHP

Ankith Reddy
Updated on 24-Jun-2020 13:42:43

44 Views

The setlocale() method is used to set locale information.Syntaxsetlocale(constant, loc)Parametersconstant − It specifies the locale information that should be set.The following are the available constants −LC_ALL  − All of the belowLC_COLLATE  − Sort orderLC_CTYPE  − Character classification and conversionLC_MESSAGES  − System message formattingLC_MONETARY  − Monetary/currency formattingLC_NUMERIC  − Numeric formattingLC_TIME  − Date and time formattingloc  − It contains the information of country or region. If the location is "0", then the location setting is not affected and only the current setting is returned.ReturnThe setlocale() function returns the current locale settings. It returns FALSE on failure.ExampleThe following is an example − Live DemoOutputen_US.UTF-8 ... Read More

rtrim() function in PHP

Samual Sam
Updated on 26-Dec-2019 07:42:00

126 Views

The rtrim() function is used to remove the white spaces from end of the string.Syntaxrtrim(str, charlist)Parametersstr − The string to checkcharlist − Specifies which characters to remove from the string. If this parameter isn’t included, then, all of the below given characters are removed −"\0" - NULL"\t" - tab"" - new line"\x0B" - vertical tab"\r" - carriage return" " - ordinary white spaceReturnThe rtrim() function returns the modified string.ExampleThe following is an example − Live DemoOutputThe following is the output −Applying rtrim(): Welcome to our website!ExampleLet us see another example − Live DemoOutputThe following is the output −Applying rtrim(): Welcome to our ... Read More

Advertisements