在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、在可以用file_get_contents替代file、fopen、feof、fgets等系列方法的情况下,尽量用 file_get_contents,因为他的效率高得多!但是要注意file_get_contents在打开一个URL文件时候的PHP版本问题;
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php class foo { function bar() { echo 'foobar'; } } $foo = new foo; // instance way $foo->bar(); // static way foo::bar(); ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php php_uname('s') == PHP_OS; php_version() == PHP_VERSION; php_sapi_name() == PHP_SAPI; ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php $is_win = DIRECTORY_SEPARATOR == '\\'; ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php $addr = strtr($addr, "abcd", "efgh"); // good $addr = strtr($addr, array('a' => 'e', // ... )); // bad ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php for ($i = 0, $max = count($array);$i < $max; ++$i); ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php // longest if ($a == $b) { $str .= $a; } else { $str .= $b; } // longer if ($a == $b) { $str .= $a; } $str .= $b; // short $str .= ($a == $b ? $a : $b); ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php // original $d = dir('.'); while (($entry = $d->read()) !== false) { if ($entry == '.' || $entry == '..') { continue; } } // versus glob('./*'); // versus (include . and ..) scandir('.'); ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php include 'file.php'; // bad approach incldue './file.php'; // good include '/path/to/file.php'; // ideal ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php $filename = "./somepic.gif"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); // vs. much simpler file_get_contents('./somepic.gif'); ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php $a['b']['c'] = array(); // slow 2 extra hash lookups per access for ($i = 0; $i < 5; ++$i) $a['b']['c'][$i] = $i; // much faster reference based approach $ref =& $a['b']['c']; for ($i = 0; $i < 5; ++$i) $ref[$i] = $i; ?>
复制代码代码如下:
// PHP CODE Highliting for CU by dZ902 <?php $a = 'large string'; // memory intensive approach function a($str) { return $str.'something'; } // more efficient solution function a(&$str) { $str .= 'something'; } ?> |
2022-08-15
2022-08-30
2022-08-17
2022-11-06
2022-08-17
请发表评论