In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge points about how php converts data types into string types. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Conversion methods: 1, the use of strval () function, syntax "strval (data value)"; 2, the use of settype () function, syntax "settype (data value,"string"); 3, the use of sprintf () function, syntax "sprintf (formatting, data value)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php converts a data type to a string type
Method 1: use the strval () function
The strval () function is used to get the string value of a variable.
Method 2: use the settype () function
The settype ($var,$type) function sets the variable $var to the specified data type $type.
The value of $type can be:
"boolean" (or "bool", starting with PHP 4.2.0)
"integer" (or "int", starting with PHP 4.2.0)
"float" (available only after PHP 4.2.0, "double" used in older versions is now disabled)
"string"
"array"
"object"
"null" (since PHP 4.2.0)
Method 3: use the sprintf () function
The sprintf () function writes the formatted string to a variable.
Description: sprintf () function
The sprintf (format,arg1,arg2,arg++) parameter is required to describe format. Specifies the string and how to format the variables in it.
Possible format values:
%%-returns a% sign
% b-binary number
Characters corresponding to% c-ASCII value
% d-Decimal number containing plus or minus sign (negative, 0, positive)
% e-use lowercase scientific counting (e.g. 1.2e+2)
% E-use uppercase scientific counting (e.g. 1.2E+2)
% u-Decimal number without plus or minus sign (greater than or equal to 0)
% f-floating point number (local setting)
% F-floating point number (non-local setting)
% g-shorter% e and% f
% G-shorter% E and% f
% o-Octal number
% s-string
% x-hexadecimal numbers (lowercase letters)
% X-hexadecimal number (uppercase)
The additional format value. Must be placed between% and letters (for example,% .2f):
+ (precede the number with + or-to define the positivity or negativity of the number. By default, only negative numbers are marked, positive numbers are not marked)
'(specifies what to use as a fill, with spaces by default. It must be used with the width specifier. For example:% 'x20s (filled with "x")
-(adjust variable value to the left)
[0-9] (specifies the minimum width of the variable value)
. [0-9] (specify the number of decimal places or the maximum string length)
Note: if you use more than one of the above format values, they must be used in the above order and cannot be disrupted.
Arg1 is required. Specifies the parameter inserted at the first% symbol in the format string. Arg2 is optional. Specifies the parameter inserted at the second% symbol in the format string. Arg++ is optional. Specifies the parameters inserted at the third, fourth, and so on% symbols in the format string.
That's all of the article "how php converts data types to string types". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.