2009四月27
thinkPHP 中那些我不知道的PHP函数
啊,这是一个很久以后才会结尾的日志,因为我也不知道我什么时候才会看完tp的源代码。
但是,我还是决定记录一些东西,因为我的脑子对这些东西总是选择遗忘。
这些函数都是PHP自带的,但是在我平时的工作中,我没有用到过。但是我认为这些都是很好用的方法。
既然有现成的,为什么不记一下,以后也方便寻找呢?呵。
呃,不要鄙视我,因为聪明的你,肯定看出来这些是PHP手册上的例子了。呵,没办法,懒。
//is_writeable -- is_writable()的别名,判断给定的文件名是否可写
$filename = 'test.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
$filename = 'test.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
/*
strpos 在字符串中查找指定字符首次出现的位置
int strpos ( string $haystack , mixed $needle [, int $offset= 0 ] ) 第三个参数指定寻找的起始位置(坐标)
$pos = 7, not 0 这个例子我认为很好
*/
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1);
strpos 在字符串中查找指定字符首次出现的位置
int strpos ( string $haystack , mixed $needle [, int $offset= 0 ] ) 第三个参数指定寻找的起始位置(坐标)
$pos = 7, not 0 这个例子我认为很好
*/
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1);
//php_strip_whitespace 去除给定PHP文件的空格及注释
// PHP comment here
/*
* Another PHP comment
*/
echo php_strip_whitespace(__FILE__);
// Newlines are considered whitespace, and are removed too:
do_nothing();
// PHP comment here
/*
* Another PHP comment
*/
echo php_strip_whitespace(__FILE__);
// Newlines are considered whitespace, and are removed too:
do_nothing();
呃,我觉得有必要把结果给一下,这还是手册上的例子-_-!!!
<?php
echo php_strip_whitespace(__FILE__); do_nothing(); ?>
echo php_strip_whitespace(__FILE__); do_nothing(); ?>
呃,因为这个函数我不确定系统函数会返回什么,所以我自己写了例子
//function_exists 返回指定函数是否已经被定义
function show()
{
echo "it's show";
}
var_dump(function_exists("echo"));//false
var_dump(function_exists("show"));//tue
function show()
{
echo "it's show";
}
var_dump(function_exists("echo"));//false
var_dump(function_exists("show"));//tue
一直在想,PHP有没有自己把自己高亮的函数,没想到,“这个还真有”
//highlight_file 把PHP文件高亮显示
function show()
{
echo "xxx";
}
/*
var_dump(function_exists("echo"));//false
var_dump(function_exists("show"));//tue
*/
highlight_file(__FILE__);
function show()
{
echo "xxx";
}
/*
var_dump(function_exists("echo"));//false
var_dump(function_exists("show"));//tue
*/
highlight_file(__FILE__);
哈,返回的结果那是相当的漂亮了。
高亮函数还有一个,叫highlight_str,呵,具体效果,自己写个例子吧?
第一天的函数先整理到这,有空继续。。
文章作者:simaopig
本文地址:http://www.xiaoxiaozi.com/2009/04/27/267/
版权所有 © 转载时必须以链接形式注明作者和原始出处!

hi小小子,不知道你能不能在一般的wp主题上实现跟iNove一样的浮动订阅器呢?
[回复]
@陶陶
就是那个RSS订阅的东西是吗?要是的话我晚上回家帮你研究一下。现在在上班。。 :cool:
[回复]
先预习一下php
[回复]
@bolo
嗯。加油加油,你是最棒的。。呵呵。。
PS:这是一款网游,人物死后系统的提示音。。 :???:
[回复]
太高深,我不懂…
[回复]
@Felix
哈哈,那你就常来捧个人场吧。哈。。
[回复]
还真是的,呵呵,来捧个人场,我也看不懂!
[回复]
@避风塘
哈哈,捧个人场也好啊。
[回复]
codecolor 函数 确实可以在新窗口中打开了
[回复]
@荒野无灯
呵呵,谢谢试验。嗯。
这个你也在用这个插件吧?用不用我把改的地方说一下?
[回复]
@simaopig
好啊,省的我看代码了,直接用你的成果啦-_-
[回复]