`
saiyaren
  • 浏览: 225768 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PHP总结 原创-胡志广

阅读更多

1.   Extract函数用法

如:

<?php

/* 假定 $var_array  wddx_deserialize 返回的数组*/

$size = “large”;

$var_array = array(”color” => “blue”,

size” => “medium”,

shape” => “sphere”);

extract($var_array, EXTR_PREFIX_SAME, “wddx”);

echo “$color, $size, $shape, $wddx_size\n”;

?>

 

上例将输出: 

blue, large, sphere, medium 

 

$size 没有被覆盖,因为指定了 EXTR_PREFIX_SAME,这使得 $wddx_size 被建立。如果指定了 EXTR_SKIP,则$wddx_size 也不会被建立。EXTR_OVERWRITE 将使 $size 的值为“medium”EXTR_PREFIX_ALL 将建立新变量$wddx_color$wddx_size  $wddx_shape 

 

如果不指定EXTR_PREFIX_SAME,那么则最新通过extract拆解的size将替换之前的变量,如:

 <?php$a = 'Original';$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");extract($my_array);echo "\$a = $a; \$b = $b; \$c = $c";?>输出:

$a = Cat; $b = Dog; $c = Horse

 

 

2.   Require错误

Warning: require(service/service.php) [function.require]: failed to open stream: No such file or directory in D:\php_project\recommand\view\recommand_goods.phpon line 2

Fatal error: require() [
function.require]: Failed opening required 'service/service.php' (include_path='.;C:\php5\pear') inD:\php_project\recommand\view\recommand_goods.php on line 

 

这是由于require相对路径引起找不到文件的,改为绝对路径,或者能够让其找到文件的相对路径也可以

 

3.   Php 全局变量函数内引用

php中声明了全局变量,然后再函数中引用,首先用global

去声明全局变量后,然后再函数内调用即可,例:

<?php

 

$product_url="http://xxxxx/product/";

function generate_current_goods($current_goods){

    global $product_url,$aaa;

    echo $product_url;

}

 

4.   Php array key value 用法

$test=array();

//写值

$test[“a”]=”aa”;

//取值

echo $test[“a”];

 

5.   php redis

$redis=new Redis();

    $redis->connect('127.0.0.1', 6379);

    //keyredis key 获取redis的字符串信息

    $redis->get(key);

    //获取hash

$goods_array=$redis->hGetAll(key);

//goods_arrayredis中获取一个array,然后获取其key

echo $goods_array[key];

 

注:

如果为hash方式通过字符串获取会出问题,会报key值不存在,这点需要注意

 

6.   Php 格式化数字

Php 格式化数字

echo number_format("1000000",2);

 

约束该数字后小数点2

 

7.   Php 判断array 是否存在

Php判断array 是否存在用null判断

If($a == NULL)

echo “test”

 

 

8.   php读数据库乱码解决方法

iconv('GB2312','UTF-8',$data)

 

 

9.  php redis hMset设置array缓存注意事项

$goods=array("wid"=>$goods_id,"wname"=>$row["Wname"],"wimageurl"=>$row["ImageUrl"],"wmaprice"=>$row["WMaprice"],"goods_current_price"=>$goods_current_price);

  $redis->hMset("d_$goods_id", $goods) ;

 

Redis如果要用redis hMset注入array缓存,那么需要用array(“xx”=>xxx)这样的方式,不能用

$a=array();

$a[‘a’]=”aa”;

这样的方式

 

10.         Php redis不能r_xxKey

Redis不能用r_xxxkey ,r_可能是redis的关键字

 

 

11.         安装php iconv错误解决方法

Make php 时报出如下错误:

ext/iconv/.libs/iconv.o(.text+0x1738): In function `zif_iconv_mime_encode':
/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1017: undefined reference to `libiconv_open'
ext/iconv/.libs/iconv.o(.text+0x1756):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1031: undefined reference to `libiconv_open'
ext/iconv/.libs/iconv.o(.text+0x1993):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1290: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x19ad):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1293: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x1b01):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1102: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1b33):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1134: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1b5e):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1150: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1e10):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1202: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1e3c):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1233: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x207f):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1277: more undefined references to `libiconv' follow

 

解决方法:

#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
#tar -zxvf libiconv-1.13.1.tar.gz
#cd libiconv-1.13.1
# ./configure --prefix=/usr/local/libiconv
# make
# make install

 

然后将php configure --with-iconv=/usr/local/libicon配置上iconv路径就可以了

 

12.         Php实现iterator

class myIterator implements Iterator

{

    //索引游标

    private $position = 0;

    private $array = array(

        "1个元素",

        "2个元素",

        "最后1个元素",

    );

 

    public function __construct()

    {

        $this->position = 0;

    }

 

    function rewind()

    {

        echo "调用rewind方法\n";

        $this->position = 0;

    }

 

    function current()

    {

        echo "调用current方法\n";

        return $this->array[$this->position];

    }

 

    function key()

    {

        echo "调用key方法\n";

        return $this->position;

    }

 

    function next()

    {

        echo "调用next方法\n";

        ++$this->position;

    }

 

    function valid()

    {

        echo "调用valid方法\n";

        return isset($this->array[$this->position]);

    }

}

 

$it = new myIterator;

$times = 0;

foreach ($it as $key => $value) {

    $times ++;

    echo "键名:{$key}  值:{$value}\n";

    echo "----------{$times}遍历完成--------->\n";

}

执行结果:

调用rewind方法
调用valid方法
调用current方法
调用key方法
键名:值:第1个元素
----------
1遍历完成--------->
调用next方法
调用valid方法
调用current方法
调用key方法
键名:值:第2个元素
----------
2遍历完成--------->
调用next方法
调用valid方法
调用current方法
调用key方法
键名:值:最后1个元素
----------
3遍历完成--------->
调用next方法
调用valid方法

 

 

Iterator调用顺序:

首次调用:

调用rewind方法
调用valid方法

如果为空则不继续调用,如果不为空继续调用
调用current方法
调用key方法

调用next方法
调用valid方法

 

 

13.         安装phpmysql错误

checking for mysql_close in -lmysqlclient... no

checking for mysql_error in -lmysqlclient... no

configure: error: mysql configure failed. Please check config.log for more information

这是因为在./configure

'--with-mysql=/export/tools/mysql-5.1.54-linux-x86_64-glibc23'这种写法是错误的,

'--with-mysql-dir=/export/tools/mysql-5.1.54-linux-x86_64-glibc23'

需要用这种写法--with-mysql-dir切记

 

 

14.         Php 编译错误lltdl错误解决方法

/usr/bin/ld: cannot find -lltdl

collect2: ld returned 1 exit status

make: *** [sapi/fpm/php-fpm] Error 1

 如果报了上述错误,那么进入到xxx/libmcrypt-2.5.8/libltdl

然后执行

./configure -enable-ltdl-install
make

Make install

然后再编译php就没有问题了

 

 

15.         Gd2总结

imagesx ( $img ) 获取图像宽度

imagesy ( $img ) 获取图像高度

 

 

2个函数需要联合使用

imagealphablending ( $img, false );

imagesavealpha ( $img, true );

16.         Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /export/data/www/xxxx/web/test_gd2_1.php on line 2

php报这个错误时:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /export/data/www/xxxx/web/test_gd2_1.php on line 2

说明第二行有语法问题

 

 

17.         iconv_substr函数

iconv_substr函数utf-8不支持中文,gbk支持中文

 

18.         正则/x7f-/xff

[a-zA-Z_/x7f-/xff]

上面表示是字母、下划线、和127-255之间的特殊字符

/x16进制

/x7f-/xff对应的就是ascii 码表的127-255的特殊字符

 

 

19.         Php 可选参数

 

<?php

   function test($a,$b="2",$c="3"){

        echo $a."|".$b."|".$c;

   }

 

   test("1");

?>

 

如果要用php 可选参数,需要在函数后面加入初值

 

20.         Fatal error: Cannot access empty property 解决方法

当抛出这个额问题时:

Fatal error: Cannot access empty property in /export/data/www/test/read_source/infertype_test.php on line 7

 

查找到第7

echo $c_test->$a."\n";

 

完全代码:

    class Test{

        public $a=11;

        static $b=2;

    }

$c_test=new Test();

         echo $c_test->a."\n";

 

这里调用

$c_test->$a,所以会出错误,把$去掉即可如:echo $c_test->a."\n";(红色为正确的)

 

21.         Redis 扩展和使用方法

Redis 扩展安装方法:

首先解压phpredis.tar.gz

$PHP_HOME:php安装目录如:/expert/servers/ php-5.3.5

 

在解压后的phpredis目录下执行:

$PHP_HOME/bin/phpize

生成redis 扩展的configure文件

 

然后执行

./configure --enable-redis --with-php-config=$PHP_HOME/bin/php-config

执行该命令后,生成redis 的扩展在php安装目录下,如:

$PHP_HOME /lib/php/extensions/no-debug-non-zts-20090626/redis.so

生成好redis.so后,在$PHP_HOME/etc/php.ini 下添加

extension=redis.so

这样redis扩展就添加到php中了

 

Redis php 使用方法:

http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html

http://seared2008.blog.51cto.com/2786540/841332

 

 

22.         解决phpIt is not safe to rely on the system's timezone settings… 

解决办法,在php.ini里加上
date.timezone = "Asia/Shanghai"

详细参见:

http://www.2cto.com/os/201210/158970.html

 

23.         soap demo no-wsdl

一、服务端-soapserver.php

 

<?php  

function add($a, $b) 

    return $a+$b; 

function test($str) 

    return $str; 

$server = new SoapServer(null, array('uri' => 'http://localhost/')); 

//$server->addFunction("add"); 

//$server->addFunction("test"); 

$server->addFunction(array('add', 'test')); 

$server->addFunction(SOAP_FUNCTIONS_ALL); 

$server->handle(); 

?> 

 

 

 

 

二、客户端-soapclient.php

 

<?php  

$arr_options = array('uri' => 'http://localhost/', 'location' => 'http://localhost/myprojects/soapserver.php', 'trace' => true); 

$soap = new SoapClient(null, $arr_options); 

echo $soap->add(20, 30);  

echo $soap->test('caleng'); 

 

参照:

http://blog.csdn.net/caleng/article/details/5427048

 

24.         Fatal error: Call to undefined function getName()错误解决方法

Fatal error: Call to undefined function getName() in /export/data/www/test/test_ext/soap/test_wsdl_class_client.php on line 9

造成这样的问题,有这么几种:

1.       getName()本身不存在,所以调用出错

2.       getName()存在,但是调用方式出了问题,如:$a->getName()正确,但是却写成了$a.getName()或者中间的调用出现了其他的错误,所以需要检查,正确的为->

 

 

25.         eclise 设计wsdl

File->other->web service

然后选择wsdl ,点击next

选择存放位置和名称,点击next

Target namespaceweb service uri,这里需要填写好;

然后点击finish

创建后生成如下内容:

1:这里是完整的web service的地址,如:

http://192.168.12.63:8082/soap/test_wsdl_server.php

2:这里的add是方法,input的是传入的参数;output是返回值;然后左边的是名称,右侧是类型

绘制内容:

1.       添加service

右键空白处,点击add service,service 相当于类

Service样式:

2.       添加binding

右键空白处,点击add Binding

点击后生成

生成binding operation代码,右键binding ,然后点击Generate Binding Content则生成bingding中的operation的代码:

生成代码如:

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="add">

<soap:operation soapAction="http://192.168.12.63:8082/soap/add"/>

<wsdl:input>

<soap:body use="literal"/>

</wsdl:input>

<wsdl:output>

<soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

……..

</wsdl:binding>

当创建新的operation需要生成operation才可以创建

3.       添加porttype

右键空白处,选择Add porttype

然后生成portType,如:

这就是一个portType,一个portType 相当于一个方法集合

4.       添加operation

Operation相当于函数或者方法,右键


5.       添加part

一个part相当于一个参数或者变量,可以定义参数的名称和返回的类型

右键一个portType

6.       添加fault

右键一个portType

点击add fault

7.       添加和设置message

右键一个portType

一个message相当于inputoutput这样的,点击set message可以进行new message和选择exsiting message

 

 

代码结构:

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://192.168.12.63:8082/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test" targetNamespace="http://192.168.12.63:8082/soap/">

<wsdl:types>

<xsd:schema targetNamespace="http://192.168.12.63:8082/soap/">

<xsd:element name="add">

<xsd:complexType>

<xsd:sequence>

<xsd:element name="in" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element name="addResponse">

<xsd:complexType>

<xsd:sequence>

<xsd:element name="out" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:schema>

</wsdl:types>

<!—这里的message的名字可以设定,这里的message相当于inputoutput,其中包括了参数和其返回值-->

<wsdl:message name="addRequest">

<!—part 就是参数,name是参数名称 type是类型,一个message中可以包含多个part-- >

<wsdl:part name="a" type="xsd:int"/>

        <wsdl:part name="b" type="xsd:int"></wsdl:part>

</wsdl:message>

<wsdl:message name="addResponse">

<wsdl:part name="returnadd" type="xsd:int"/>

</wsdl:message>

   

    <wsdl:message name="test_input1">

    <wsdl:part name="str" type="xsd:string"></wsdl:part>

    </wsdl:message>

    <wsdl:message name="test_out_1">

    <wsdl:part name="returnstr" type="xsd:string"></wsdl:part>

    </wsdl:message>

    <!—这个是portType的标识-->

    <wsdl:portType name="test">

<!—这里是operation的声明块,名字是方法名称,然后其中的input是输入,也就是传入的参数,message是上面声明好的message,然后output是返回值,引用上面声明好的message-->

<wsdl:operation name="add">

<wsdl:input message="tns:addRequest"/>

<wsdl:output message="tns:addResponse"/>

</wsdl:operation>

 

 

 

 

        <wsdl:operation name="test">

        <wsdl:input message="tns:test_input1"></wsdl:input>

        <wsdl:output message="tns:test_out_1"></wsdl:output>

        </wsdl:operation>

    </wsdl:portType>

<!—这里声明的是binding的内容 typeportType-- > 

    <wsdl:binding name="testSOAP" type="tns:test">

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<!—这里是binding中的方法(operation -- >

<wsdl:operation name="add">

<soap:operation soapAction="http://192.168.12.63:8082/soap/add"/>

<wsdl:input>

<soap:body use="literal"/>

</wsdl:input>

<wsdl:output>

<soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name="test">

<soap:operation soapAction="http://192.168.12.63:8082/soap/test"/>

<wsdl:input>

<soap:body use="literal"/>

</wsdl:input>

<wsdl:output>

<soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<!—这里定义的是service 的内容-->

<wsdl:service name="test">

<wsdl:port binding="tns:testSOAP" name="testSOAP">

<soap:address location="http://192.168.12.63:8082/soap/test_wsdl_server.php"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

 

 

26.         Soap demo wsdl 模式

Function soap实现:

Server:

<?php

//wsdl不缓存

ini_set("soap.wsdl_cache_enabled", "0");

//实现方法

function add($a, $b)

{

        return $a+$b;

}

function test($str)

{

        return $str;

}

//加载模板

$server = new SoapServer('test.wsdl');

//将函数添加到server

$server->addFunction(array('add', 'test'));

//添加handle

$server->handle();

//遍历server中的方法进行读取

$functions = $server->getFunctions();

foreach($functions as $func) {

        echo $func . "\n";

}

 

?>

Client:

<?php

ini_set("soap.wsdl_cache_enabled", "0");

//创建soapClient对象,加载wsdl

$soap = new SoapClient('http://192.168.12.63:8082/soap/test.wsdl');

//读取soap中的存在的方法

print_r($soap->__getFunctions());

//调用方法

echo $soap->add(13,22);

echo $soap->test("aaa");

 ?>

 

Soap类实现:

Server:

<?php

ini_set("soap.wsdl_cache_enabled", "0");

    class test_class{

        function getName($name){

            return $name;

        }

        function __construct()

          {

                echo "aaaaaaaaaaaaa";

          }

    }

$server = new SoapServer('test_class.wsdl');

//function的区别就在于,声明好的类,这里设置上类名即可

$server->setClass("test_class");

$server->handle();

$functions = $server->getFunctions();

foreach($functions as $func) {

        echo $func . "\n";

}

 

?>

 

Client:

<?php

ini_set("soap.wsdl_cache_enabled", "0");

$soap = new SoapClient('http://192.168.12.63:8082/soap/test_class.wsdl');

 

 print_r($soap->__getFunctions());

/*server中的类的函数直接加载进来了,一般来说soap中的一个wsdl就是一个类的概念

所以这里创建client后,然后直接调用方法即可

*/

echo $soap->getName("testName");

 ?>

 

 

27.         设置wsdl缓存

ini_set("soap.wsdl_cache_enabled", "0");

 

 

28.         phpinfo 无法显示问题解决  

配置php.ini文件
disable_functions = passthru, exec, phpinfo, system, ini_alter, readlink, symlink, leak, proc_open, popepassthru, chroot, scandir, chgrp, chown, escapeshellcmd, escapeshellarg, shell_exec, proc_get_status


这一句中去掉phpinfo

去掉phpinfo后就可以显示phpinfo

 

29.         call_user_func_array()

例子:

<?php

function foobar($arg, $arg2) {

    echo __FUNCTION__, " got $arg and $arg2\n";

}

class foo {

    function bar($arg, $arg2) {

        echo __METHOD__, " got $arg and $arg2\n";

    }

}

 

 

// Call the foobar() function with 2 arguments

call_user_func_array("foobar", array("one", "two"));

 

// Call the $foo->bar() method with 2 arguments

$foo = new foo;

call_user_func_array(array($foo, "bar"), array("three", "four"));

?>

call_user_func_array详解

第一参数是函数名或array(对象,方法)

第二个参数是参数集合

 

30.         安装mssql 扩展

./configure  --with-php-config=/export/servers/php-5.3.5/bin/php-config --with-mssql=/export/servers/freetds

然后make –j 16

报了如下错误:

In file included from /export/software/php/php-5.3.5/ext/mssql/php_mssql.c:33:

/export/software/php/php-5.3.5/ext/mssql/php_mssql.h:67: error: redefinition of typedef 'LPBYTE'

/export/servers/freetds/include/sqlfront.h:35: note: previous declaration of 'LPBYTE' was here

/export/software/php/php-5.3.5/ext/mssql/php_mssql.c: In function 'php_mssql_do_connect':

/export/software/php/php-5.3.5/ext/mssql/php_mssql.c:760: warning: cast from pointer to integer of different size

/export/software/php/php-5.3.5/ext/mssql/php_mssql.c: In function 'php_mssql_get_column_content_without_type':

/export/software/php/php-5.3.5/ext/mssql/php_mssql.c:1113: warning: passing argument 1 of 'spprintf' from incompatible pointer type

/export/servers/php-5.3.5/include/php/main/spprintf.h:40: note: expected 'char **' but argument is of type 'unsigned char **'

Php 扩展和freetds都定义了LPBYTE类型

Freetds是在sqlfront.h:35定义的

Php_ext是在php_mssql.h:67定义的

所以php_ext中重复定义了

我们注释掉php_mssql.h:67行的LPBYTE类型即可

然后再编译就没有问题了

Make

Make install

编译完成后,我们在php.ini中加入mssql.so即可

 

31.         获取的php不加转义符

magic_quotes_gpc=Off

magic_quotes_runtime=Off

magic_quotes_sybase=Off

 

php.ini中配置,如果不配置,会出现转义符/

 

 

32.         Php 关闭安全模式

php报了如下错误时:

Warning: require() [function.require]: SAFE MODE Restriction in effect. The script whose uid is 502 is not allowed to access /export/data/www/club_ice_lib/Ice.php owned by uid 506 in/export/data/www/test/thinkphp_test/ThinkPHP_3.0_Full/Examples/Hello/Lib/Action/IndexAction.class.php on line 10

 

Php 默认开启安全模式

php.ini中将

safe_mode = Off

设置为关闭,重启即可

或者给提示无法访问的目录分配用户权限也可以

 

33.         Unset销毁对象

Php中的unset函数是用于销毁对象的;

例:

$a=new A();

Unset($a);

 

$a=null;

也会销毁对象

也就是销毁对象有2种:nullunset

 

34.         Php文件操作

$f1=fopen("logs/test_file.log","a");

if(!$f1){

        echo "file don't exists";

        exit;

}

fwrite($f1,"test!");

fclose($f1);

 

参考:

http://blog.sina.com.cn/s/blog_55f6ef710100l3jl.html

 

35.         获取引用的所有文件

print_r(get_included_files());

 

 

36.         create_function 用法(匿名函数)

$newfunc = create_function('$a,$b,$c', 'return $a.$b.$c;');

echo "New anonymous function: $newfunc\n";

echo $newfunc(2, 3,"aaa") . "\n";

 

 

create_function(传入参数,执行代码)

 

传入参数如:

$a,$b,$c,这个就是类似function a($a,$b,$c)

执行代码:

'return $a.$b.$c;',这里也可以任意写为’echo aaa;’

 

然后创建好匿名函数后,赋值给$newfunc

在下面通过$newfunc(2,3,”aaa”)这样调用,括号内是传入参数,有别于普通的函数普通函数前不需要加$,这里执行的匿名函数是赋值给了 一个变量,这里需要注意

 

create_function 伪造主函数内容

 

create_function实现过程:

<?php

function __lambda_func(替换参数位置){

         替换语句位置

}

 

 

如果create_function 如下实现:

create_function('', '} echo "hi"; if (0) {');

 

参数为空:

那么替换参数位置不需要替换;

然后替换语句位置替换为:} echo "hi"; if (0) {

最终拼接后的语句为:

 

<?php

 

function __lambda_func(){

 

}

 

echo "hi";

 

if(0){

 

}

 

这样其实echo “hi”;就形成了一个伪造主函数;

Hhvm中需要通过:

invokeFunc(&retval, unit->getMain(), Array::Create());

调用一次主函数进行调用(目前存在泄露)

 

正常替换过程为:

(1)       替换参数

(2)       替换内容

(3)       替换__lambda_func为对象名

 

37.         Warning: Cannot modify header information - headers already sent by (output

 

PHP报如下错误时:

Warning: Cannot modify header information - headers already sent by (output started at /export/data/www/test/test_ext/iconv/test_iconv.php:1) in /export/data/www/test/test_ext/iconv/test_iconv.php on line 3

 

设置php.ini

output_buffering=on

重启php即可

 

38.         Php json使用

<?php

 class myClass {

     public $item1 = 1;

     public $item2 = 'aa';

 }

 

 $c = new myClass();

 echo json_encode($c);

 ?>

 

39.         Array加入栈

$a=array();

array_push($a,”aaa”);

 

 

40.         ldap 扩展安装

cd php-5.3.5/ext/ldap

./configure --with-php-config=/export/servers/php-5.3.5/bin/php-config

报了如下错误;

configure: error: Cannot find ldap libraries in /usr/lib.

 

这是由于默认是查找的/usr/lib ldap的包是在/usr/lib64

./configure --with-php-config=/export/servers/php-5.3.5/bin/php-config --with-ldap --with-libdir=lib64/

 

通过--with-ldap --with-libdir=lib64 指定到lib64下即可(因为默认前面已经加上了/usr/….

然后运行configure成功

  • 大小: 29.9 KB
  • 大小: 39.3 KB
  • 大小: 38.8 KB
  • 大小: 26.3 KB
  • 大小: 5.6 KB
  • 大小: 5.2 KB
  • 大小: 5.6 KB
  • 大小: 14.5 KB
  • 大小: 5.6 KB
  • 大小: 15.3 KB
  • 大小: 18 KB
  • 大小: 1.4 KB
  • 大小: 15.8 KB
  • 大小: 15.8 KB
  • 大小: 15.8 KB
  • 大小: 1.3 KB
1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics