首页 > 编程技术 > php

‘大公司’的PHP面试题

发布时间:2016-11-25 16:08

http://topic.111cn.net/u/20071202/16/e53996de-4725-4dfa-bf14-c197afeed93c.html

 

 



<?php
class engage
{
    
public function getArray()
    {
        
$arr1 = array (
        
''0'' => array (''fid'' => 1, ''tid'' => 1, ''name'' => ''Name1'' ),
        
''1'' => array (''fid'' => 1, ''tid'' => 2 , ''name'' => ''Name2'' ),
        
''2'' => array (''fid'' => 1, ''tid'' => 5 , ''name'' => ''Name3'' ),
        
''3'' => array (''fid'' => 1, ''tid'' => 7 , ''name'' => ''Name4'' ),
        
''4'' => array (''fid'' => 3, ''tid'' => 9, ''name'' => ''Name5'' )
        );
        
$arr2 = array();
        
foreach ($arr1 as $key => $value)
        {
            
$arr2[$value[''fid'']][] = array(''tid'' => $value[''tid''],''name'' => $value[''name'']);
        }
        
return $arr2;
    }
    
//print_r($arr2);
    //$eString = ''open_door'';

    public function getString($eString = null)
    {
        
$eString = explode(''_'',$eString);
        
$eString = array_map("ucfirst",$eString);
        
$eString = implode($eString,'''');
        
return  $eString;
    }
    
/**
     * 冒泡排序 
     * @return unknown
     
*/
    
public function getBubble()
    {
        
$isOver = false;
        
$bubbleArray =  array(10,2,36,14,10,25,23,85,99,45);
        
$bubbleResult = $bubbleArray;
        
do{
            
$bubbleArray = $bubbleResult;
            
$isOver = true;
            
foreach ($bubbleArray as $key => $value)
            {
                
if ($value < $bubbleResult[$key-1])
                {
                    
$bubbleResult[$key]=$bubbleResult[$key-1];
                    
$bubbleResult[$key-1]=$value;
                    
$isOver = false;
                }
            }
        }
while (!$isOver);
        
return $bubbleResult;
    }

}
$engage = new engage();
print_r($engage->getArray());
echo $engage->getString(''make_by_id'');
print_r($engage->getBubble());
?>
</pre>

 

 



<?php
/**
 * 第二题正则替换实现.
 *
 
*/
function getString($eString = null)

    
$eString = preg_replace(array("/(^[a-z]{1}|_[a-z]{1})/e",''/_/''),
                            
array("strtoupper(''1'')",''''),
                            
$eString);
    
return  $eString;
}
?>


<

<?php 
/**
 * session处理器 
 * memcache 实现
 * @author MoXie SysTem128@GMail.Com 
 
*/ 
class SessionHandler extends Memcache
{
    
public $_sessionId;             # session 编号
    public $_sessionExpire;         # session 过期时间
    public $_sessionIsQuery;
    
public function __construct()
    {
        
$this->_sessionExpire = 600;
        
$this->connect(''localhost'',11211);
    }
    
/**
     * 获取所有定位字段 
     * 
     
*/ 

    
/**
   * 读取 Session 
   * 
   * @return unknown 
   
*/ 
    
public function getSession($snKey)
    {
        
$returnInfo = $this->get($snKey);
        
$this->_sessionIsQuery = (bool)$returnInfo;
        
return $returnInfo;
    }
    
/**
   *  插入新的Session 
   
*/ 
    
public function insertSession($snKey,$value)
    {
        
return $this->set($snKey,$value,0,$this->_sessionExpire);
    }
    
/**
   * 更新session信息 
   * 
   * @return unknown 
   
*/ 
    
public function updateSession($snKey,$value)
    {
        
# 修改语句
        return  $this->set($snKey,$value,0,$this->_sessionExpire);
    }
    
/**
   * 删除Session 
   * 
   * @return unknown 
   
*/ 
    
public function delSession($snKey)
    {
        
return $this->delete($snKey,0);
    }
    
/**
   * 删除过期 Session 
   * 
   * @return unknown 
   
*/ 
    
public function expireSession()
    {
        
return true;
    }
    
/**
   * session 启动器 
   * 
   
*/ 

    
public function on_session_start()
    {
        
$this->_sessionSite = 1;
        
$this->_sessionId = session_id();
        
return true;
    }
    
/**
   * session 终止 
   
*/ 
    
public function on_session_end()
    {
        
return $this->expireSession();
    }
    
/**
   * 读取方法 
   * 
   * @param unknown_type $key 
   
*/ 
    
public function on_session_read($key)
    {
        
return $this->getSession($key);
    }
    
/**
   * 写入方法 
   * 
   * @param unknown_type $key 
   * @param unknown_type $value 
   
*/ 
    
public function on_session_write($key,$value)
    {
        
$this->getSession($key);
        
if ($this->_sessionIsQuery)
        {
            
$this->updateSession($key,$value);
        }
else{
            
$this->insertSession($key,$value);
        }
        
return true;
    }
    
/**
   * 销毁方法 
   * 
   * @param unknown_type $key 
   
*/ 
    
public function on_session_destroy($key)
    {
        
return $this->delSession();
    }
    
/**
   * 过期方法 
   * 
   * @param integer $maxLifeTime 
   
*/ 
    
public function on_session_gc($maxLifeTime)
    {
        
return $this->expireSession();
    }
}

$sessionHandler = new SessionHandler();
session_set_save_handler(
array(&$sessionHandler,''on_session_start''),
array(&$sessionHandler,''on_session_end''),
array(&$sessionHandler,''on_session_read''),
array(&$sessionHandler,''on_session_write''),
array(&$sessionHandler,''on_session_destroy''),
array(&$sessionHandler,''on_session_gc'')
);
unregister_tick_function(''session_write_close'');

session_start();
//$_SESSION[''MoXie''] = ''Wonderfull!'';
//$_SESSION[''SysTem128''] = ''Wonderfull!'';
//session_unregister(''MoXie'');

print_r($_SESSION);
?>  

了解如何使用 Asynchronous JavaScript™ + XML (Ajax) 和 PHP 在 Web 应用程序中建立聊天系统。您的客户不需要下载或安装任何专门的即时消息通讯软件,就能和您及其他客户讨论网站的内容。

Web 2.0 一词出现以来,开发人员都在说社区。不论您是否认为这有点夸大其辞,但让用户或读者能够方便地实时讨论页面主题或者销售的产品,这一想法还是很吸引人的。但是怎么办呢?能否在推销产品的页面中加入聊天,而不必让客户安装任何特殊的软件包括 Adobe Flash Player 呢?当然!实践证明,用免费的现成工具如 PHP、MySQL、动态 HTML (DHTML)、Ajax 和 Prototype.js 库就能完全做到。

不再罗嗦了,让我们立即开始吧。 


本文转自:IBM developerWorks 中国
请点击此处查看全文

忙了一整天都没有成果,突然想起看一下appserv的配置文件,果然通过了。欢喜中。。。记下来先。
使用软件版本:
apache_2.2.6-win32-x86-openssl-0.9.8e.msi
mysql-5.0.45-win32.exe
php-5.2.5-Win32.zip
phpMyAdmin-2.11.2.2-all-languages.zip

1.安装apache到d:serverapache2.2
2.安装MySQL到d:servermysql5
3.解压php到d:serverphp
4.拷贝php文件夹下的libmysql.dll到c:windowssystem32目录下;
5.拷贝php文件夹下的php.ini-recommended到c:windows下并改名为php.ini
--------------------------------------------------------------------
6.打开apache的配置文件httpd.conf
    a.在有许多LoadModule处添加一行:
        LoadModule php5_module d:/Serverphpphp5apache2_2.dll
    b.修改DocumentRoot "e:/www" 这是放置网页的根目录,自己想设置在什么地方就设置在什么地方。
    c.# This should be changed to whatever you set DocumentRoot to.
        <Directory "e:/www">
       找到这里以后,把原来<Directory "">中的路径改成和b一样的路径。
    d.在DirectoryIndex index.html处添加index.htm index.php
    e.最后在<IfModule></IfModule>附近添加再添加一段
        <IfModule mod_php5.c>
              AddType application/x-httpd-php .php
              AddType application/x-httpd-php .php3
              AddType application/x-httpd-php-source .phps
        </IfModule>
------------------------------------------------------------------------
7.打开在c:windows下的php.ini文件
    a.将一下语句前的;符号去掉
        extension=php_dbase.dll
        extension=php_gd2.dll
        extension=php_mbstring.dll
        extension=php_mysql.dll
        extension=php_mysqli.dll
        extension=php_sockets.dll
 &nbs 随着adobe的FLEX和ROMTING的开源化又引起一场的RIA风波,我作为传统的WEB开发人员被其深深的吸引,作为web开发人员很关注flash如何和后台连接,在网上苦苦寻找终于发现了,在AS3下如何和后台通信,其实FLASH ROMTING 和JAVA DWR设计很相似都是通过中间来转化后台和前台对象,今天我就以一个金典的HELLOWORLD程序来展现这个框架。
        首先到http://www.amfphp.org下
标签:[!--infotagslink--]