久艹网,亚洲一日韩欧美中文字幕2019,国产欧美日韩精品专区黑人,一区二区三区久久99

中山php|最優(yōu)網(wǎng)絡中山做網(wǎng)站 中山php建站

最優(yōu)良人

2011/08/18 at 21:47

php函數(shù)體里調(diào)用外部變量

在程序開發(fā)中,有時在一個函數(shù)里面需要調(diào)用到函數(shù)體以外的變量,這個時候有幾種方法

可以再聲明變量的時候聲明為全局變量,如:

global $string;

$string = 'test';

function __(){
return $string;
}

也可以在函數(shù)的內(nèi)部聲明,如:

$string = 'test';

function __(){

global $string;
return $string;
}

當需要調(diào)用的變量只有少數(shù)的時候可以這樣用,那么如果是需要使用大量已經(jīng)定義過的變量或者甚至是全部變量的時候如何處理呢?可以這樣處理,用到PHP的超全局數(shù)組$GLOBALS和extract()函數(shù)

PHP手冊對$GLOBAL的說明是這樣的:

An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

Note: This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods.

大概意思是:

這個一個由所有變量組成的數(shù)組。變量名就是該數(shù)組的索引。并且該數(shù)組是超全局數(shù)組,在使用時不必聲明global $variable;

extract()函數(shù)的作用是把數(shù)組的鍵名作為變量名,數(shù)組的鍵值作為變量的值。

所以綜上所述,只要在函數(shù)體里面寫上下面一句話就可以實現(xiàn)調(diào)用到外部的所有變量了

$string = 'test';

$num = 100;

function __(){

echo$string,$num;
}

extract($GLOBALS,EXTR_SKIP);

標簽:,
comments Comments (26)    -
2011/08/18 at 17:47

div li元素不限定寬度,如何浮在中間

div的橫向居中我們都知道而已用margin:0 auto;實現(xiàn),但是在不指定寬度的情況下這語句是沒有意義的,div為塊級元素,在內(nèi)層DIV未指定寬度的情況下不能通過margin:0 auto來實現(xiàn)居中,將其轉(zhuǎn)換為內(nèi)聯(lián)元素(display:inline)后在外層DIV加text-align:center才能居中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
<div style="width:800px;height:300px;text-align:center;margin:0 auto;background:#efefef;"><div style="background:#ff33cc;display:inline;">sdaasddsa</div></div>
</body>
</html>

標簽:, , , ,
comments Comments (498)    -
2011/08/18 at 14:53

如何避免谷歌搜索被重置

使用google搜索時,經(jīng)常遇到一件很糾結(jié)的事情就是突然搜索結(jié)果就被重置了,特別是使用谷歌搜索工具這個好用的東東的時候,基本上是用不了,想看最近24小時博客的收錄情況,要換好幾個瀏覽器,一般的解決方法是翻墻去搜索,但是速度不敢恭維。

最近發(fā)現(xiàn)一種比較簡單的方法,就是通過遨游的多重搜索,在谷歌用搜索工具的時候暫時還沒被墻過,暗喜……

comments Comments (190)    -
2011/08/18 at 14:42

按鈕變成失效狀態(tài),input框變成只讀模式以及CSS一些頁面控制

以下代碼可以使按鈕變成失效狀態(tài)
<input id="select-layout" type="button" value="布置圖管理" name="select-layout" disabled="disabled">

以下代碼可以使input框變成只讀且禁用模式
<input name="demo" type="text" disabled value="value" readonly="true" />

CSS控制字數(shù)多,隱藏多余字
text-overflow:ellipsis;word-break:keep-all;overflow:hidden; white-space:nowrap;

顯示豎的滾動條
overflow-y:auto;height:220px;

//表格不被撐開,換行
style="word-break:break-all"

控制input或者textarea背景透明的樣式
background-color: transparent;

實現(xiàn)細邊的表格
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<tr bgcolor="#eff3ff">
<td>標題:用戶:</td>
</tr>
<tr bgColor="#ffffff">
<td>內(nèi)容:</td>
</tr>
</table>
或者簡單通過這個屬性控制
style="border-collapse:collapse"

標簽:
comments Comments (200)    -
2011/08/18 at 14:38

php獲取遠程圖片,下載到本地-readfile,file_get_contents函數(shù)

php獲取遠程圖片的原理是使用readfile函數(shù)讀入一個遠程文件的stream,然后寫入一個文件生成本地圖片

注:也可以用file_get_contents函數(shù),二者的區(qū)別是readfile直接把文件stream輸出,而后者賦給變量。

以下自定義函數(shù)可以實現(xiàn)遠程圖片獲取,并自動下載為本地文件:

<?php
//
// Function: 獲取遠程圖片并把它保存到本地
//
//
// 確定您有把文件寫入本地服務器的權(quán)限
//
//
// 變量說明:
// $url 是遠程圖片的完整URL地址,不能為空。
// $filename 是可選變量: 如果為空,本地文件名將基于時間和日期
// 自動生成.
function GrabImage($url,$filename="") {
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dMYHis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
$img=GrabImage("/Article/UploadFiles/201003/20100313135251414.jpg","");
if($img):echo '<pre><img src="'.$img.'"></pre>';
else:echo "false";
endif;
?>

標簽:
comments Comments (16)    -
2011/08/18 at 14:26

把網(wǎng)站頁面自動提交到搜索引擎

很多搜索引擎都提供了博客地址的提交入口,可以把我們博客的網(wǎng)址或者文章地址提交到他們的數(shù)據(jù)庫以供索引,其中有些在提交過程中需要輸入驗證碼,如百度,有道;有些則不需要,如谷歌,騰訊搜搜;不需要輸入驗證碼的入口我們可以通過寫程序把文章自動提交到搜索引擎。

下面是一些搜索引擎提供的博客搜索服務:
http://blogsearch.google.com/ 谷歌博客搜索

http://blogsearch.baidu.com/ 百度博客搜索

http://blog.soso.com/ 騰訊搜搜博客搜索:可以搜QQ空間
http://blog.youdao.com/ 網(wǎng)易有道博客搜索:有一些有趣的數(shù)據(jù)整理方式
下面則是這些搜索引擎相應提供的提交博客入口:
http://blogsearch.google.com/ping?hl=zh-CN google博客提交入口
http://utility.baidu.com/blogsearch/submit.php 百度博客提交入口,有驗證碼
http://tellbot.youdao.com/report?type=BLOG 有道博客提交入口,有驗證碼
http://blog.soso.com/join.html 騰訊搜搜博客搜索提交入口


博客ping服務地址:

ping是基于XML_RPC標準協(xié)議的更新通告服務,是用于blog在內(nèi)容更新時通知博客搜索引擎及時進行抓取、更新的方式。博客搜索引擎在成功接受到ping以后,會立刻進行抓取并更新。使用ping服務,可以讓博客搜索引擎在第一時間抓取到您博客上的新內(nèi)容。

http://blogsearch.google.com/ping/rpc2 谷歌博客搜索ping服務
http://ping.baidu.com/cgi-bin/blog 百度博客搜索ping服務
http://blog.youdao.com/ping/RPC2 網(wǎng)易有道博客搜索ping服務

 

下面的代碼是天涯博客實現(xiàn)博客的博文自動提交,其他網(wǎng)站頁面的提交道理也是相同的,都是利用博客的自動ping服務:

 

<form id=frm_google_ping name=frm_google_ping action=http://blogsearch.google.com/ping method=get target="iframe__google_ping">
<input type="hidden" name="name" value="tianyablog" ID="Hidden4">
<input type="hidden" name="url" value="http://www.dgkai.cn/" ID="Hidden5">
<input type="hidden" name="changesURL" value="http://www.dgkai.cn/blog/about" ID="Hidden6">
</form>
<iframe name="iframe__google_ping" src="" width="0" height="0"></iframe>
<br><br>
<form id=frm_soso_ping name=frm_soso_ping action="http://tep.soso.com/cgi-bin/pingd.fcgi" method=get target="iframe_soso_ping">
<input type="hidden" name="soso_url" value="tianyablog" ID="sosoHidden4">
<input type="hidden" name="soso_url" value="http://www.dgkai.cn/ " ID="sosoHidden5">
<input type="hidden" name="soso_url" value="http://www.dgkai.cn/" ID="sosoHidden6">
</form>
<iframe name="iframe_soso_ping" src="" width="0" height="0"></iframe>

 

標簽:
comments Comments (437)    -
2011/08/16 at 10:31

FleaPHP頁面控件 WebControls的使用

如果不使用模板引擎,需要先注冊控件 $ui =& FLEA::initWebControls() ;其實就是返回控件的實例,該函數(shù)的代碼是

00662 function & initWebControls()
00663 {
00664 return FLEA::getSingleton(FLEA::getAppInf('webControlsClassName'));
00665 }

'webControlsClassName'默認是FLEA目錄下的webControls類,該類封裝了頁面組件的實現(xiàn),以及一些常用的頁面控件,在找不到這些自帶控件的時候就會去嘗試搜索我們自定義的以_ctl開頭的控件

/**
* 構(gòu)造一個控件的 HTML 代碼
*
* @param string $type
* @param string $name
* @param array $attribs
* @param boolean $return
*
* @return string
*/
function control($type, $name, $attribs = null, $return = false)
{
$type = strtolower($type);
$render = '_ctl' . ucfirst($type);
$attribs = (array)$attribs;

$__ctl_out = false;
if (method_exists($this, $render)) {
$__ctl_out = $this->{$render}($name, $attribs);
} else {
$extfilename = ucfirst($type) . '.php';
if (!isset($this->_extends[$type])) {
foreach ($this->_extendsDir as $dir) {
if (file_exists($dir . DS . $extfilename)) {
require($dir . DS . $extfilename);
$this->_extends[$type] = true;
break;
}
}
}

if (isset($this->_extends[$type])) {
$__ctl_out = call_user_func_array($render,
array('name' => $name, 'attribs' => $attribs));
}
}

if ($__ctl_out === false) {
$__ctl_out = "INVALID CONTROL TYPE \"{$type}\"";
}

if ($return) { return $__ctl_out; }
echo $__ctl_out;
return '';
}

實例化控件之后,在模版(也就是 .php)中:

1 <?php
2 $ui->control('textbox', 'username',
3 array(
4 'class' => 'textbox',
5 'size' => 28,
6 'maxlength' => 22,
7 )
8 );
9 ?>

如果使用smarty,調(diào)用方式就是:

{ webcontrol type='textbox' value=$textbox_value }
系統(tǒng)會自動去實例化控件對象

標簽:,
comments Comments (318)    -
2011/08/15 at 16:08

PHP利用header函數(shù)實現(xiàn)各種狀態(tài)的跳轉(zhuǎn)

header實現(xiàn)301永久重定向
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.dgkai.cn");

header實現(xiàn)302臨時重定向
Header("HTTP/1.1 302 Found");
Header("Location: http://www.dgkai.cn");

header實現(xiàn)404無法找到頁面
Header("HTTP/1.1 404 Not Found");

一下函數(shù)可實現(xiàn)各種狀態(tài)的跳轉(zhuǎn):

/**
* 跳轉(zhuǎn)頁面
*
* 使用header()進行頁面跳轉(zhuǎn),不顯示任何內(nèi)容.如果不能使用header跳轉(zhuǎn)
* @param string $url
* @param int $status
*/
function goto($url,$status=null)
{
if(!empty($status))
{
$status=intval($status);
$codes = array(
100 => "Continue",
101 => "Switching Protocols",
200 => "OK",
201 => "Created",
202 => "Accepted",
203 => "Non-Authoritative Information",
204 => "No Content",
205 => "Reset Content",
206 => "Partial Content",
300 => "Multiple Choices",
301 => "Moved Permanently",
302 => "Found",
303 => "See Other",
304 => "Not Modified",
305 => "Use Proxy",
307 => "Temporary Redirect",
400 => "Bad Request",
401 => "Unauthorized",
402 => "Payment Required",
403 => "Forbidden",
404 => "Not Found",
405 => "Method Not Allowed",
406 => "Not Acceptable",
407 => "Proxy Authentication Required",
408 => "Request Time-out",
409 => "Conflict",
410 => "Gone",
411 => "Length Required",
412 => "Precondition Failed",
413 => "Request Entity Too Large",
414 => "Request-URI Too Large",
415 => "Unsupported Media Type",
416 => "Requested range not satisfiable",
417 => "Expectation Failed",
500 => "Internal Server Error",
501 => "Not Implemented",
502 => "Bad Gateway",
503 => "Service Unavailable",
504 => "Gateway Time-out"
);
if (array_key_exists($status,$codes)) {
$code = $status;
$msg = $codes[$status];
$status = "HTTP/1.1 {$code} {$msg}";
} else {
$status = null;
}
}
if (!empty($status)) {
header($status);
}
if(!empty($url)) {
$url=url($url);header("Location: $url");
if ($code==404) {
echo "<meta http-equiv='refresh' content='0;url=$url'>";
}
}
exit;
}

標簽:,
comments Comments (250)    -
2011/08/15 at 09:58

HTML表單里面使用fieldset,legend標簽,實現(xiàn)標題浮在邊線上的效果

經(jīng)??吹揭恍┍韱螘幸环N相同的特殊效果,就是表單說明文字會浮在邊線上,可以用css控制實現(xiàn),但是其實html有一個fieldset標簽來實現(xiàn)這效果
HTML <fieldset> 標簽

定義和用法

fieldset 元素可將表單內(nèi)的相關(guān)元素分組。

<fieldset> 標簽將表單內(nèi)容的一部分打包,生成一組相關(guān)表單的字段。

當一組表單元素放到 <fieldset> 標簽內(nèi)時,瀏覽器會以特殊方式來顯示它們,它們可能有特殊的邊界、3D 效果,或者甚至可創(chuàng)建一個子表單來處理這些元素。

<fieldset> 標簽沒有必需的或唯一的屬性。

<legend> 標簽為 fieldset 元素定義標題。

實例

組合表單中的相關(guān)元素:

<form>

<fieldset>

<legend>health information</legend>

height: <input type="text" />

weight: <input type="text" />

</fieldset>

</form>
實現(xiàn)效果如下

health information

height:

weight:

還可以用css控制邊線的樣式和legend的樣式。

<form>

<fieldset>

<legend>health information</legend>

height: <input type="text" />

weight: <input type="text" />

</fieldset>

</form>

標簽:,
comments Comments (293)    -
2011/08/15 at 01:19

php正則匹配時常用到的模式修正符

PHP簡單的模版引擎主要的原理是使用preg_replace對模板的內(nèi)容進行替換,替換成可執(zhí)行的php語句然后寫入緩存文本,再include進來執(zhí)行。

在使用preg_replace時常用到的模式修正符有:

e:$replacement 的字符串將被當作php語句執(zhí)行

U:禁止貪婪匹配 只跟蹤到最近的一個匹配符并結(jié)束,

m:在匹配首內(nèi)容或者尾內(nèi)容時候采用多行識別匹配

s:模式中的圓點元字符(.)匹配所有的字符,包括換行

標簽:,
comments Comments (267)    -