无需言 做自己 业 ,精于勤 荒于嬉.

杂项 函数 __halt_compiler 中断编译器的执行

发表日期:2021-07-01 10:15:42 | 来源: | 分类:杂项 函数

      示例1
<?php 
// open this file$fp = fopen(__FILE__, 'r');
// seek file pointer to datafseek($fp, __COMPILER_HALT_OFFSET__);
// and output itvar_dump(stream_get_contents($fp));
// the end of the script execution__halt_compiler();
 the installation data (eg. tar, gz, PHP, etc.)

阅读全文 »

杂项 函数 highlight_string 字符串的语法高亮

发表日期:2021-07-01 10:15:42 | 来源: | 分类:杂项 函数

      示例1
<?php 
highlight_string('<?php phpinfo();
 ?>');
?>

阅读全文 »

杂项 函数 exit 输出一个消息并且退出当前脚本

发表日期:2021-07-01 10:15:42 | 来源: | 分类:杂项 函数

      示例1
<?php 
$filename = '/path/to/data-file';
$file = fopen($filename, 'r')    or exit("unable to open file ($filename)");
?>

      示例2
<?php 
//exit program normallyexit;
exit();
exit(0);
//exit with an error codeexit(1);
exit(0376);
 //octal?>

      示例3
<?php 
class Foo{
    public function __destruct()    {
        echo 'Destruct: ' . __METHOD__ . '()' . PHP_EOL;
    }
}
function shutdown(){
    echo 'Shutdown: ' . __FUNCTION__ . '()' . PHP_EOL;
}
$foo = new Foo();
register_shutdown_function('shutdown');
exit();
echo 'This will not be output.';
?>

阅读全文 »

杂项 函数 hrtime 获取系统的高精度时间

发表日期:2021-07-01 10:15:42 | 来源: | 分类:杂项 函数

      示例1
<?php 
echo hrtime(true), PHP_EOL;
print_r(hrtime());
?>

阅读全文 »

杂项 函数 pack 将数据打包成二进制字符串

发表日期:2021-07-01 10:15:42 | 来源: | 分类:杂项 函数

      示例1
<?php 
$binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);
?>

阅读全文 »

SimpleXML 函数 simplexml_import_dom Get a SimpleXMLElement object from a DOM node

发表日期:2021-07-01 08:57:25 | 来源: | 分类:SimpleXML 函数

      示例1
<?php 
$dom = new DOMDocument;
$dom->loadXML('<books><book><title>blah</title></book></books>');
if (!$dom) {
    echo 'Error while parsing the document';
    exit;
}
$s = simplexml_import_dom($dom);
echo $s->book[0]->title;
?>

阅读全文 »

SimpleXML 函数 simplexml_load_string Interprets a string of XML into an object

发表日期:2021-07-01 08:57:25 | 来源: | 分类:SimpleXML 函数

      示例1
<?php 
$string = <<<XML<?xml version='1.0'?> <document> <title>Forty What?</title> <from>Joe</from> <to>Jane</to> <body>  I know that's the answer -- but what's the question? </body></document>XML;
$xml = simplexml_load_string($string);
print_r($xml);
?>

阅读全文 »

SimpleXML 函数 simplexml_load_file Interprets an XML file into an object

发表日期:2021-07-01 08:57:25 | 来源: | 分类:SimpleXML 函数

      示例1
<?php 
// The file test.xml contains an XML document with a root element// and at least an element /[root]/title.if (file_exists('test.xml')) {
    $xml = simplexml_load_file('test.xml');
     print_r($xml);
}
 else {
    exit('Failed to open test.xml.');
}
?>

阅读全文 »

变量处理 函数 is_float 检测变量是否是浮点型

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

is_float

(PHP 4, PHP 5, PHP 7, PHP 8)

is_float检测变量是否是浮点型

描述

is_float(mixed $var): bool

如果 varfloat 则返回 true,否则返回 false

注意:

若想测试一个变量是否是数字或数字字符串(如表单输入,它们通常为字符串),必须使用 is_numeric()

参见 is_bool()is_int()is_integer()is_numeric()is_string()is_array()is_object()

阅读全文 »

变量处理 函数 is_null 检测变量是否为 null

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

is_null

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

is_null 检测变量是否为 null

描述

is_null(mixed $var): bool

如果 varnull 则返回 true,否则返回 false

查看 null 类型获知变量什么时候被认为是 null,而什么时候不是。

参见 nullis_bool()is_numeric()is_float()is_int()is_string()is_object()is_array()is_integer()is_real()

阅读全文 »

变量处理 函数 is_object 检测变量是否是一个对象

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

is_object

(PHP 4, PHP 5, PHP 7, PHP 8)

is_object检测变量是否是一个对象

描述

is_object(mixed $var): bool

如果 var 是一个 object 则返回 true,否则返回 false

参见 is_bool()is_int()is_integer()is_float()is_string()is_array()

阅读全文 »

变量处理 函数 is_resource 检测变量是否为资源类型

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

is_resource

(PHP 4, PHP 5, PHP 7, PHP 8)

is_resource 检测变量是否为资源类型

描述

is_resource(mixed $var): bool

如果给出的参数 varresource 类型,is_resource() 返回 true,否则返回 false

查看 resource 类型文档获取更多的信息。

阅读全文 »

变量处理 函数 is_string 检测变量是否是字符串

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

is_string

(PHP 4, PHP 5, PHP 7, PHP 8)

is_string检测变量是否是字符串

描述

is_string(mixed $var): bool

如果 varstring 则返回 true,否则返回 false

参见 is_bool()is_int()is_integer()is_float()is_real()is_object()is_array()

阅读全文 »

变量处理 函数 is_long is_int() 的别名

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

is_long

(PHP 4, PHP 5, PHP 7, PHP 8)

is_longis_int() 的别名

描述

此函数是 is_int() 的别名函数。

阅读全文 »

变量处理 函数 isset 检测变量是否已设置并且非 null

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

      示例1
<?php 
$var = '';
// 结果为 TRUE,所以后边的文本将被打印出来。if (isset($var)) {
    echo "This var is set so I will print.";
}
// 在后边的例子中,我们将使用 var_dump 输出 isset() 的返回值。// the return value of isset().$a = "test";
$b = "anothertest";
var_dump(isset($a));
      // TRUEvar_dump(isset($a, $b));
 // TRUEunset ($a);
var_dump(isset($a));
     // FALSEvar_dump(isset($a, $b));
 // FALSE$foo = NULL;
var_dump(isset($foo));
   // FALSE?>

      示例2
<?php 
$a = array ('test' => 1, 'hello' => NULL, 'pie' => array('a' => 'apple'));
var_dump(isset($a['test']));
            // TRUEvar_dump(isset($a['foo']));
             // FALSEvar_dump(isset($a['hello']));
           // FALSE// 键 'hello' 的值等于 NULL,所以被认为是未置值的。// 如果想检测 NULL 键值,可以试试下边的方法。 var_dump(array_key_exists('hello', $a));
 // TRUE// Checking deeper array valuesvar_dump(isset($a['pie']['a']));
        // TRUEvar_dump(isset($a['pie']['b']));
        // FALSEvar_dump(isset($a['cake']['a']['b']));
  // FALSE?>

      示例3
<?php 
$expected_array_got_string = 'somestring';
var_dump(isset($expected_array_got_string['some_key']));
var_dump(isset($expected_array_got_string[0]));
var_dump(isset($expected_array_got_string['0']));
var_dump(isset($expected_array_got_string[0.5]));
var_dump(isset($expected_array_got_string['0.5']));
var_dump(isset($expected_array_got_string['0 Mostel']));
?>

阅读全文 »

变量处理 函数 print_r 以易于理解的格式打印变量。

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

      示例1
<pre><?php 
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?></pre>
      示例2
<?php 
$b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
$results = print_r($b, true);
 // $results 包含了 print_r 的输出?>

阅读全文 »

变量处理 函数 settype 设置变量的类型

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

      示例1
<?php 
$foo = "5bar";
 // string$bar = true;
   // booleansettype($foo, "integer");
 // $foo 现在是 5   (integer)settype($bar, "string");
  // $bar 现在是 "1" (string)?>

阅读全文 »

变量处理 函数 serialize 产生一个可存储的值的表示

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

      示例1
<?php 
// $session_data 是包含了当前用户 session 信息的多维数组。// 我们使用 serialize() 在请求结束之前将其存储到数据库中。$conn = odbc_connect ("webdb", "php", "chicken");
$stmt = odbc_prepare ($conn,      "UPDATE sessions SET data = ? WHERE id = ?");
$sqldata = array (serialize($session_data), $PHP_AUTH_USER);
if (!odbc_execute ($stmt, &$sqldata)) {
    $stmt = odbc_prepare($conn,     "INSERT INTO sessions (id, data) VALUES(?, ?)");
    if (!odbc_execute($stmt, &$sqldata)) {
    /* 出错 */
    }
}
?>

阅读全文 »

变量处理 函数 is_scalar 检测变量是否是一个标量

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

      示例1
<?php 
function show_var($var){
    if (is_scalar($var)) {
        echo $var;
    }
 else {
        var_dump($var);
    }
}
$pi = 3.1416;
$proteins = array("hemoglobin", "cytochrome c oxidase", "ferredoxin");
show_var($pi);
show_var($proteins)?>

阅读全文 »

变量处理 函数 unset 释放给定的变量

发表日期:2021-07-01 08:57:22 | 来源: | 分类:变量处理 函数

      示例1
<?php 
function destroy_foo() {
    global $foo;
    unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
?>

      示例2
<?php 
function foo() {
    unset($GLOBALS['bar']);
}
$bar = "something";
foo();
?>

      示例3
<?php 
function foo(&$bar) {
    unset($bar);
    $bar = "blah";
}
$bar = 'something';
echo "$bar\n";
foo($bar);
echo "$bar\n";
?>

      示例4
<?php 
function foo(){
    static $bar;
    $bar++;
    echo "Before unset: $bar, ";
    unset($bar);
    $bar = 23;
    echo "after unset: $bar\n";
}
foo();
foo();
foo();
?>

      示例5
<?php 
// 销毁单个变量unset ($foo);
// 销毁单个数组元素unset ($bar['quux']);
// 销毁一个以上的变量unset($foo1, $foo2, $foo3);
?>

      示例6
<?php 
$name = 'Felipe';
var_dump((unset) $name);
var_dump($name);
?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。