分类: 系统运维
2011-09-27 14:08:27
$str = '此次8468058万元';
$preg = '#[0-9]{1,}#';
preg_match_all($preg,$str,$match);
echo $match[0][0];
?>
$dira = dirname(dirname(__FILE__)) . $DS . "webroot".$DS."attachment".$DS."product".$number.".xlsx" ;
//download the excel file
header( "Content-type: application/excel" );
header( "Content-disposition: attachment; filename=".basename($dira) );
header( "Content-transfer-encoding: binary\n");
header( "Content-length: " . @filesize($dira ) . "\n" );
// Send the torrent file
$fp = @fopen( $dira, "r" );
@fpassthru( $fp );
@fclose( $fp );
?>
class mysql
{
private function __construct($configs){
//print_r($configs);
$this->_databaseHost = $configs['databaseHost'];
$this->_databaseUser = $configs['userName'];
$this->_databaseName = $configs['databaseName'];
$this->_passWord = $configs['passWord'];
//$this->_databaseHost = '192.168.4.99';
//$this->_databaseUser = 'asskuaibo';
//$this->_databaseName = 'asskuaibo';
//$this->_passWord = 'asskuaibo';
//print_r($configs);
$this->_init();
}
private function __clone(){}
private function _init(){
try{
$this->_link = mysql_connect($this->_databaseHost, $this->_databaseUser, $this->_passWord) or die('can not connect mysql!!');
mysql_query("set names '".$this->_charset."'");
mysql_select_db ($this->_databaseName, $this->_link);
}catch (Exception $e){
echo 'exception';
}
}
public function get($sql){
//echo $sql;
if($this->_isDebug()){
echo "$sql
";
}
$res = mysql_query($sql, $this->_link);
while($row = mysql_fetch_assoc($res)){
$data[] = $row;
}
//var_dump($data);
return $data;
}
public function query($sql){
if($this->_isDebug()){
echo "$sql
";
}
mysql_query($sql, $this->_link);
}
/**
* only one instance
*
*
* */
public static function getInstance($configs){
if(self::$_instance === null){
self::$_instance = new self($configs);
}
return self::$_instance;
}
private function _isDebug(){
return $this->_isDebug;
}
public function onDebug(){
$this->_isDebug = true;
}
public function offDebug(){
$this->_isDebug = false;
}
private $_isDebug = false;
private $_link = null;
private static $_instance = null;
private $_databaseHost = null;
private $_databaseUser = null;
private $_passWord = null;
private $_charset = 'utf8';
private $_databaseName = null;
}
class request
{
public static function get($key, $default = ''){
if(isset($_POST[$key])){
return self::_filter($_POST[$key]);
}else if(isset($_GET[$key])){
return self::_filter($_GET[$key]);
}else {
return $default;
}
}
public static function _filter($str){
return addslashes($str);
}
}
class mem_cache
{
public function set($key, $val, $cacheTime){
$this->_memcache->set($key, $val, 0, $cacheTime);
}
public function get($key){
return $this->_memcache->get($key);
}
public function del($key){
$this->_memcache->delete($key);
}
public function delAll(){
$this->_memcache->flush();
}
public static function getInstance($mem_config){
if(self::$_instance === null){
self::$_instance = new self($mem_config);
}
return self::$_instance;
}
private function __clone(){}
private function __construct($mem_config){
//$this->_config = $mem_config;
//print_r($mem_config);
$this->_config['host'] = $mem_config['host'];
$this->_config['port'] = $mem_config['port'];
//$this->_config['host'] = '192.168.3.24';
//$this->_config['port'] = 11211;
if($this->_memcache === null){
$this->_memcache = new Memcache;
$this->_memcache->connect($this->_config['host'], $this->_config['port']);
}
}
private static $_instance = null;
private $_mem = null;
private $_config = array();
}
class apc_cache
{
public function set($key, $val, $cacheTime){
apc_store($key, $val, $cacheTime);
}
public function get($key){
return apc_fetch($key);
}
public function del($key){
apc_delete($key);
}
public function delAll(){
apc_clear_cache("user");
}
public static function getInstance(){
if(self::$_instance === null){
self::$_instance = new self();
}
return self::$_instance;
}
private static $_instance = null;
}
class cache
{
public static function getInstance( $mem_config = array(), $type = 'a'){
if($type == 'a'){
return apc_cache::getInstance();
}else{
//var_dump($mem_config);
return mem_cache::getInstance($mem_config);
}
}
public function __construct(){
}
}
?>