16. The HEBREVC () function converts a right-to-left stream of Hebrew text to a left-to-right stream. It also converts the new line (\ n) to <br/>. Only ASCII characters between 224 and 251, as well as punctuation marks, are affected.
Syntax: Hebrev (string,maxcharline)
MAXCHARLINE Specifies the maximum number of characters per line. If possible, Hebrev () will avoid breaking the word. Tip: Hebrev () and HEBREVC () can convert Hebrew logical text to Hebrew visible text. Hebrew visible text does not require special right-to-left character support, which makes it useful for displaying Hebrew text on the web.
17. The Htmlspecialchars () function converts some pre-defined characters to HTML entities.
The predefined characters are:
- & (and number) becomes &
- "(double quotes) become "
- ' (single quotes) become & #039;
- < (less than) becomes <
- > (greater than) becomes >
Syntax: Htmlspecialchars (String,quotestyle,character-set)
quotestyle--is optional. Specifies how to encode single and double quotation marks.
- Ent_compat-Default. Encodes only double quotes.
- Ent_quotes-encodes double and single quotation marks.
- Ent_noquotes-do not encode any quotation marks.
character-set--is optional. A string value that specifies the character set to use.
- Iso-8859-1-Default. Western europe.
- Iso-8859-15-Western Europe (added Euro symbol and French, Finnish alphabet).
- UTF-8-ASCII-compatible multi-byte 8-bit Unicode
- Cp866-dos dedicated Cyrillic Character Set
- Cp1251-windows dedicated Cyrillic Character Set
- Cp1252-windows Special Western European character set
- Koi8-r-Russian
- GB2312-Simplified Chinese, national standard character set
- BIG5-Traditional Chinese
- Big5-hkscs-big5 Hong Kong expansion
- Shift_JIS-Japanese
- EUC-JP-Japanese
Hint: A character set that cannot be recognized is ignored and replaced by Iso-8859-1. Example
< HTML >
The < body >
<!--?</span--> PHP
$STR = "John & 'Adams' ";
Echo htmlspecialchars ($STR, ENT_COMPAT);
Echo "< br / >";
Echo htmlspecialchars ($STR, ENT_QUOTES);
Echo "< br / >";
Echo htmlspecialchars ($STR, ENT_NOQUOTES);
? >
The < / body >
The < / HTML >
Browser output:
John & 'Adams'
John & 'Adams'
John & 'Adams'
If you look at the source code in a browser, you'll see this HTML:
< HTML >
The < body >
John & amp; "Adams' < br / >
John & amp; The & # 039; Adams & # 039; < br / >
John & amp; Adams' '
The < / body >
The < / HTML >
The htmlspecialchars_decode() function, which converts some predefined HTML entities to characters, is the inverse of htmlspecialchars().
Grammar: htmlspecialchars_decode (string, quotestyle)
Quotestyle is specified by htmlspecialchars().
The implode() function combines the array elements into a string.
Grammar: the implode (separator, array)
The separator - optional. Specifies what to put between array elements. The default is "" (empty string).
Array - required. An array to be combined as a string.
Note: although the separator parameter is optional. However, for backward compatibility, it is recommended that you use two parameters. Comment: implode() can take two orders of arguments. However, due to historical reasons, being () is not acceptable. You must make sure the separator parameter precedes the string parameter. example
<!--?</span--> PHP
$arr = array (" Hello ", "World! ', 'Beautiful', 'Day! ');
Echo the implode (" ", $arr);
? >
Output:
Hello World! Beautiful Day!
The join() function combines the elements of an array into a string. The join() function is an alias for the implode() function.
The levenshtein() function returns the levenshtein distance between two strings.
Levenshtein distance, also known as edit distance, refers to the minimum number of edits required to convert from one string to the other between two strings. The permitted editing operations include replacing one character with another, inserting a character, and deleting a character.
For example kitten to sitting:
Sitten (k, s)
Sittin (e - > I)
Sitting (- > g)
The levenshtein() function gives each operation (replace, insert, and delete) the same weight. However, you can define the cost of each operation by setting the optional insert, replace, and delete parameters.
Grammar: the levenshtein (string1, string2, insert, replace, delete)
Parameters to describe
String1 required. The first string to compare.
String2 required. The second string to compare.
The insert is optional. The cost of inserting a character. The default is 1.
Replace the optional. The cost of replacing a character. The default is 1.
Delete the optional. The cost of deleting a character. The default is 1.
Note:
If one of the strings is more than 255 characters long, the levenshtein() function returns -1. The levenshtein() function is case-insensitive. The levenshtein() function is faster than the similar_text() function. However, the similar_text() function provides more precise results that require less modification.
example
<!--?</span--> PHP
Echo the levenshtein (" Hello World ", "ello World");
Echo "< br / >";
Echo the levenshtein (" Hello World ", "ello World", 10, 30);
? >
Output:
1
30
The localeconv() function returns an array of local numeric and monetary information formats.
23. The ltrim() function deletes Spaces or other predefined characters from the left side of the string. Functions like chop() or rtrim();
The md5() function evaluates the md5 hash of a string. The md5() function USES RSA data security, including the md5 message extraction algorithm. Returns the computed MD5 hash on success, or false on failure.
Grammar: md5 (string, raw)
Raw - optional. Specified hexadecimal or binary output format:
TRUE - original 16 character binary format
FALSE - default. A 32-character hexadecimal number
Note: this parameter was added in PHP 5.0.
The md5_file() function evaluates the MD5 hash of the file. The md5() function USES RSA data security, including the md5 message extraction algorithm. Returns the computed MD5 hash on success, or false on failure.
Example 1
<!--?</span--> PHP
$filename = "test. TXT";
$md5file = md5_file ($filename);
Echo $md5file;
? >
Output:
5 d41402abc4b2a76b9719d911017c592
The metaphone() function computes the metaphone key of a string. Metaphone key string pronunciation in English. The metaphone() function is used in spell-checking applications.
The metaphone key of the string is returned on success and false on failure.
Grammar: the metaphone (string, length)
Length - optional. Specifies the maximum length of the metaphone key. Explanation: metaphone() creates the same keys for words that sound similar. The generated metaphone key is of variable length. The metaphone() function is more precise than the soundex() function because metaphone() understands the basic rules of English pronunciation. Example: example 1
<!--?</span--> PHP
Echo the metaphone (" world ");
? >
Output:
WRLT
Example 2
In this example, we use the metaphone() function for two similar-sounding words:
<!--?</span--> PHP
$STR = "Sun";
$str2 = "Son";
Echo the metaphone ($STR);
Echo the metaphone ($str2);
? >
Output:
SN
SN
27. The money_format() function formats a string as a currency string.
Grammar: money_format (string, number)
The number of optional. The number into which the % symbol position is inserted in the formatted string. Note: the money_format() function does not work on Windows platforms. Example: example 1
International en_US format:
<!--?</span--> PHP
$number = 1234.56;
The setlocale (LC_MONETARY, "en_US");
Echo money_format("The price is % I ", $number);
? >
Output:
The price is USD 1,234.56
Example 2
Negative number, US international format with () indicating a negative number, accuracy of the right is 2, "*" is the filling character:
<!--?</span--> PHP
$number = 1234.5672;
Echo money_format (" % = * (# 10.2 n ", $number);
? >
Output:
($* * * * * * * * 1234.57)
28. The nl_langinfo() function returns the specified local information.
If successful, the specified local information is returned. If this fails, false is returned. Grammar: the nl_langinfo (element)
Element - required. Specify which element to return. Must be one of the elements listed in the specification. Description:
Time and calendar:
ABDAY_ (1-7) - Abbreviated name of the numbered day of the week
DAY_ (1-7) - the Name of the numbered day of the week (DAY_1 = Sunday)
ABMON_ (1-12) - Abbreviated name of the numbered the month of the year
MON_ (1-12) - the Name of the numbered the month of the year
Am_str-string for Ante meridian
Pm_str-string for Post meridian
D_t_fmt-string that can be used as the format String for strftime() to represent time and date
D_fmt-string that can be used as the format String for strftime() to represent date
T_FMT - String that can be used as the format String for strftime() to represent time
T_FMT_AMPM - String that can be used as the format String for strftime() to represent time in 12-hour format with ante/post meridian
ERA - Alternate ERA
Era_year-year in alternate era format
Era_d_t_fmt-date and time in alternate era format (string can be used in strftime())
Era_d_fmt-date in alternate era format (string can be used in strftime())
Era_t_fmt-time in alternate era format (string can be used in strftime())
Currency category:
INT_CURR_SYMBOL - Currency symbol (example: USD)
CURRENCY_SYMBOL - Currency symbol (example: $)
CRNCYSTR - Same as CURRENCY_SYMBOL
Mon_decimal_point-monetary decimal point character
Mon_thousands_sep-monetary thousands separator
Positive_sign-positive value character
NEGATIVE_SIGN - Negative value character
MON_GROUPING - Array displaying how monetary Numbers are grouped (example: 1, 000, 000)
INT_FRAC_DIGITS - International fractional digits
FRAC_DIGITS - Local fractional digits
P_CS_PRECEDES - True (1) if currency symbol is placed in front of a positive value, False (0) if it is placed behind
P_sep_by_space-true (1) if there is a space between the currency symbol and a positive value, False (0) otherwise
N_CS_PRECEDES - True (1) if currency symbol is placed in front of a negative value, False (0) if it is placed behind
N_sep_by_space-true (1) if there is a space between the currency symbol and a negative value, False (0) otherwise
P_SIGN_POSN - Formatting setting.possible return values:
0 - Parentheses surround the quantity and the currency symbol
1 - The sign string is placed in front of The quantity and currency symbol
2 - The sign string is placed after The quantity and currency symbol
3 - The sign string is placed immediately in front of The currency symbol
4 - The sign string is placed immediately after The currency symbol
N_SIGN_POSN - Formatting setting.possible return values:
0 - Parentheses surround the quantity and the currency symbol
1 - The sign string is placed in front of The quantity and currency symbol
2 - The sign string is placed after The quantity and currency symbol
3 - The sign string is placed immediately in front of The currency symbol
4 - The sign string is placed immediately after The currency symbol
Number category:
Decimal_point-decimal point character
Radixchar-same as DECIMAL_POINT
Thousands_sep-separator character for thousands
Thousep-same as THOUSANDS_SEP
The GROUPING - Array displaying how Numbers are grouped (example: 1, 000, 000)
Type of communication:
YESEXPR - Regex string for matching 'yes' input
NOEXPR - Regex string for matching 'no' input
Yesstr-output string for 'yes'
Nostr-output string for 'no'
Code set category:
CODESET Return a string with the name of the character encoding.
Hints and comments
Note: the money_format() function does not work on Windows platforms.
Tip: unlike the localeconv() function, which returns all local formatting information, nl_langinfo() returns the specified information.
The nl2br() function inserts the HTML newline character (
) before each new line in the string (\n).
Grammar: nl2br (string)
<!--?</span--> PHP
Echo nl2br (" One line. \ nAnother line. ");
? >
Output:
One line.
Another line.
HTML code:
One line. < br / >
Another line.
The number_format() function formats Numbers by grouping them in thousands. Grammar: of number_format (number, decimals, decimalpoint, the separator)
Number of required. The number to format. If no other parameters are set, the number is formatted with no decimal point and separated by a comma (,).
Decimals - optional. Specify how many decimals. If the parameter is set, the dot (.) is used as the decimal point to format the number.
Decimalpoint - optional. Specifies a string to be used as a decimal point.
The separator - optional. Specifies a string to be used as a thousand separator. Only the first character of the parameter is used. For example, "xyz" only outputs "x". Note: if this parameter is set, all other parameters are required. Note: this function supports one, two, or four arguments (not three). example
<!--?</span--> PHP
The echo of number_format (" 1000000 ");
The echo of number_format (" 1000000 ", 2);
The echo of number_format (" 1000000 ", 2, ", ", "");
? >
Output:
1000000
1000000.00
00 1.000.000,
PHP learning series (1) -- string handling functions (4)