draw_string函数
The is_string() PHP function is used to check if a type of variable is a string. A string is a data type, such as floating point or integer, but it represents text rather than numbers. A string uses a set of characters that includes spaces and numbers. For instance, an address such as "1234 Broadway" and the sentence "I ate 3 hotdogs" contain numbers that should be treated as text, not as numbers.
PHP函数is_string()用于检查变量的类型是否为字符串。 字符串是数据类型,例如浮点数或整数,但是它表示文本而不是数字。 字符串使用一组包含空格和数字的字符。 例如,一个地址(例如“ 1234 Broadway”)和句子“ I ate 3 hotdogs”包含应被视为文本而非数字的数字。
如何使用功能 ( How to Use the Function )
Is_string is used within an if () statement to treat strings in one way and non-strings in another. It returns true or false. For example:
在if()语句中使用Is_string以一种方式处理字符串,以另一种方式处理非字符串。 它返回true或false。 例如:
<?php
if (is_string(23))
{
echo "Yes";
} else {
echo "No";
}
?>
The code above should output "No" because 23 is not a string. Let's try this again:
上面的代码应该输出“ No”,因为23不是字符串。 让我们再试一次:
<?php
if (is_string("Hello World"))
{
echo "Yes";
} else {
echo "No";
}
?>
Since "Hello World" is a string, this would echo "Yes."
由于“ Hello World ”是字符串,因此将回显“是”。
指定一个字符串 ( Specifying a String )
A string can be specified in four ways:
可以通过四种方式指定字符串:
- Single quoted 单引号
- Double quoted 双引号
- Heredoc syntax Heredoc语法
- Nowdoc Syntax Nowdoc语法
Each of these methods requires strict adherence to PHP rules, which are available at the PHP website. The simplest method, single-quoted strings, requires special treatment when literal single quotation marks or literal backslashes appear in the string. Include a backslash in front of the single quotation mark or backslash within the string. The example below illustrates this treatment:
这些方法中的每一种都必须严格遵守PHP规则,该规则可在PHP网站上获得。 最简单的方法,即单引号字符串,当在字符串中出现文字单引号或文字反斜杠时,需要进行特殊处理。 在单引号前面包括反斜杠,或者在字符串中包括反斜杠。 下面的示例说明了这种处理方法:
<?php
// Outputs: Arnold said: "I'll be back"
echo 'Arnold said: "I\'ll be back"';
// Outputs: I deleted C:\*.*?
echo 'I deleted C:\\*.*?';
?>
类似功能 ( Similar Functions )
is_float() – determines if the type of variable is float
is_float() –确定变量的类型是否为float
is_int() – determines if the type of variable is integer
is_int() –确定变量的类型是否为整数
is_bool() – determines if a variable is a boolean
is_bool() –确定变量是否为布尔值
is_object() – determines if a variable is an object
is_object() –确定变量是否为对象
is_array() – determines if a variable is an array
is_array() –确定变量是否为数组
is_numeric() – determines if a value is a number or a numeric string
is_numeric() –确定值是数字还是数字字符串
翻译自: https://www.thoughtco.com/isstring-php-function-2694103
draw_string函数