缂栫▼棰�:
1. 鍐欎竴涓嚱鏁帮紝灏藉彲鑳介珮鏁堢殑锛屼粠涓�涓爣鍑� url 閲屽彇鍑烘枃浠剁殑鎵╁睍鍚�
渚嬪:http://www.sina.com.cn/abc/de/fg.PHP?id=1闇�瑕佸彇鍑� php 鎴� .php
绛旀1:
function getExt($url){
$arr = parse_url($url);
$file = basename($arr['path']);
$ext = explode(".",$file);
return $ext[1];
}
绛旀2:
function getExt($url) {
$url = basename($url);
$pos1 = strpos($url,".");
$pos2 = strpos($url,"?");
if(strstr($url,"?")){
return substr($url,$pos1 + 1,$pos2 -$pos1 - 1);
} else {
return substr($url,$pos1);
}
}
2. 鍦� HTML 璇█涓紝椤甸潰澶撮儴鐨� meta鏍囪鍙互鐢ㄦ潵杈撳嚭鏂囦欢鐨勭紪鐮佹牸寮忥紝浠ヤ笅鏄竴涓爣鍑嗙殑 meta 璇彞
璇蜂娇鐢� PHP 璇█鍐欎竴涓嚱鏁帮紝鎶婁竴涓爣鍑� HTML 椤甸潰涓殑绫讳技 meta 鏍囪涓殑 charset 閮ㄥ垎鍊兼敼涓� big5
璇锋敞鎰�:
1. 闇�瑕佸鐞嗗畬鏁寸殑 html 椤甸潰锛屽嵆涓嶅厜姝� meta 璇彞
2. 蹇界暐澶у皬鍐�
3. ' 鍜� " 鍦ㄦ澶勬槸鍙互浜掓崲鐨�
4. 'Content-Type' 涓や晶鐨勫紩鍙锋槸鍙互蹇界暐鐨勶紝浣� 'text/html; charset=gbk' 涓や晶鐨勪笉琛�
5. 娉ㄦ剰澶勭悊澶氫綑绌烘牸
$str=File_get_contents(鈥榵xx.php鈥�);
Preg_replace(鈥�//鈥�,鈥�//鈥�,$str锛�
3. 鍐欎竴涓嚱鏁帮紝绠楀嚭涓や釜鏂囦欢鐨勭浉瀵硅矾寰�
濡� $a ='/a/b/c/d/e.php';
$b ='/a/b/12/34/c.php';
璁$畻鍑� $b 鐩稿浜� $a 鐨勭浉瀵硅矾寰勫簲璇ユ槸 ../../c/d灏�()娣讳笂
绛�:function getRelativePath($a, $b) {
$returnPath = array(dirname($b));
$arrA = explode('/', $a);
$arrB = explode('/', $returnPath[0]);
for ($n = 1, $len = count($arrB); $n <$len; $n++) {
if ($arrA[$n] != $arrB[$n]) {
break;
}
}
if ($len - $n > 0) {
$returnPath = array_merge($returnPath,array_fill(1, $len - $n, '..'));
}
$returnPath = array_merge($returnPath,array_slice($arrA, $n));
return implode('/', $returnPath);
}
echo getRelativePath($a, $b);
濉┖棰�:
1.鍦≒HP涓紝褰撳墠鑴氭湰鐨勫悕绉�(涓嶅寘鎷矾寰勫拰鏌ヨ瀛楃涓�)璁板綍鍦ㄩ瀹氫箟鍙橀噺__$_SERVER['PHP_SELF']__涓�;鑰岄摼鎺ュ埌褰撳墠椤甸潰鐨刄RL璁板綍鍦ㄩ瀹氫箟鍙橀噺__$_SERVER['HTTP_REFERER']__
涓�
2.鎵ц绋嬪簭娈靛皢杈撳嚭__0__銆�
3.鍦℉TTP 1.0涓紝鐘舵�佺爜 401 鐨勫惈涔夋槸__鏈鎺堟潈__;濡傛灉杩斿洖鈥滄壘涓嶅埌鏂囦欢鈥濈殑鎻愮ず锛屽垯鍙敤 header 鍑芥暟锛屽叾璇彞涓篲_header(鈥榣ocation:xxx.php鈥�)__銆�
4.鏁扮粍鍑芥暟 arsort 鐨勪綔鐢ㄦ槸__瀵规暟缁勮繘琛岄�嗗悜鎺掑簭骞朵繚鎸佺储寮曞叧绯籣_;璇彞error_reporting(2047)鐨勪綔鐢ㄦ槸__鎶ュ憡鎵�鏈夐敊璇拰璀﹀憡__銆�
5.PEAR涓殑鏁版嵁搴撹繛鎺ュ瓧绗︿覆鏍煎紡鏄痏_銆�
6.鍐欏嚭涓�涓鍒欒〃杈惧紡锛岃繃铏戠綉椤典笂鐨勬墍鏈塉S/VBS鑴氭湰(鍗虫妸scr墨pt鏍囪鍙婂叾鍐呭閮藉幓鎺�):preg_replace("/].*?>.*?/si","newinfo", $script);
7.浠pache妯″潡鐨勬柟寮忓畨瑁匬HP锛屽湪鏂囦欢http.conf涓鍏堣鐢ㄨ鍙___鍔ㄦ�佽杞絇HP妯″潡锛岀劧鍚庡啀鐢ㄨ鍙___浣垮緱Apache鎶婃墍鏈夋墿灞曞悕涓簆hp鐨勬枃浠堕兘浣滀负PHP鑴氭湰澶勭悊銆�
LoadModule php5_module "c:/php/php5apache2.dll" ,
AddTypeapplication/x-httpd-php .php,
8.璇彞 include 鍜� require 閮借兘鎶婂彟澶栦竴涓枃浠跺寘鍚埌褰撳墠鏂囦欢涓紝瀹冧滑鐨勫尯鍒槸____;涓轰簡閬垮厤澶氭鍖呭惈鍚屼竴鏂囦欢锛屽彲浠ョ敤璇彞__require_once||include_once__鏉ヤ唬鏇垮畠浠��
9.绫荤殑灞炴�у彲浠ュ簭鍒楀寲鍚庝繚瀛樺埌 session 涓紝浠庤�屼互鍚庡彲浠ユ仮澶嶆暣涓被锛岃繖瑕佺敤鍒扮殑鍑芥暟鏄痏_unserialize__銆�
10.涓�涓嚱鏁扮殑鍙傛暟涓嶈兘鏄鍙橀噺鐨勫紩鐢紝闄ら潪鍦╬hp.ini涓妸__allow_call_time_pass_reference boolean__璁句负on.
11.SQL涓璍EFT JOIN鐨勫惈涔夋槸__鑷劧宸﹀閾炬帴__銆傚鏋� tbl_user璁板綍浜嗗鐢熺殑濮撳悕(name)鍜屽鍙�(ID)锛宼bl_score璁板綍浜嗗鐢�(鏈夌殑瀛︾敓鑰冭瘯浠ュ悗琚紑闄や簡锛屾病鏈夊叾璁板綍)鐨勫鍙�(ID)
鍜岃�冭瘯鎴愮哗(score)浠ュ強鑰冭瘯绉戠洰(subject)锛岃鎯虫墦鍗板嚭鍚勪釜瀛︾敓濮撳悕鍙婂搴旂殑鐨勫悇绉戞�绘垚缁╋紝鍒欏彲浠ョ敤SQL璇彞__select聽 *聽 fromtbl_user left jion tbl_score on tbl_user.id=tbl_score.uid__銆�
12.鍦≒HP涓紝heredoc鏄竴绉嶇壒娈婄殑瀛楃涓诧紝瀹冪殑缁撴潫鏍囧織蹇呴』____銆�
<<
Sdashkdhklahdklh
EOT
缂栫▼棰�:
13.鍐欎竴涓嚱鏁帮紝鑳藉閬嶅巻涓�涓枃浠跺す涓嬬殑鎵�鏈夋枃浠跺拰瀛愭枃浠跺す銆�
绛�:
function my_scandir($dir)
{
$files = array();
if ( $handle = opendir($dir) ) {
while ( ($file = readdir($handle)) !==false ) {
$file=$dir.鈥�/鈥�.$file
if ( $file != ".."&& $file != "." ) {
if ( is_dir($dir ."/" . $file) ) {
$files[$file] =scandir($dir . "/" . $file);
}else {
$files[] = $file;
}
}
}
closedir($handle);
return $files;
}
}
14.绠�杩拌鍧涗腑鏃犻檺鍒嗙被鐨勫疄鐜板師鐞嗐��
绛�:
/*
鏁版嵁琛ㄧ粨鏋勫涓�:
CREATE TABLE `category` (
`categoryID` smallint(5) unsigned NOT NULLauto_increment,
`categoryParentID` smallint(5) unsigned NOTNULL default '0',
`categoryName` varchar(50) NOT NULL default'',
PRIMARY KEY (`categoryID`)
) ENGINE=MyISAM DEFAULTCHARSET=gbk;
INSERT INTO `category` (`categoryParentID`, `categoryName`) VALUES
(0, '涓�绾х被鍒�'),
(1, '浜岀骇绫诲埆'),
(1, '浜岀骇绫诲埆'),
(1, '浜岀骇绫诲埆'),
(2, '涓夌骇绫诲埆'),
(2, '333332'),
(2, '234234'),
(3, 'aqqqqqd'),
(4, '鍝堝搱'),
(5, '66333666');
*/
//鎸囧畾鍒嗙被id鍙橀噺$category_id,鐒跺悗杩斿洖璇ュ垎绫荤殑鎵�鏈夊瓙绫�
//$default_category涓洪粯璁ょ殑閫変腑鐨勫垎绫�
functionGet_Category($category_id = 0,$level = 0, $default_category = 0)
{
global $DB;
$sql = "SELECT * FROM category ORDER BYcategoryID DESC";
$result = $DB->query( $sql );
while ($rows = $DB->fetch_array($result))
{
$category_array[$rows[categoryParentID锛絒$rows[categoryID锛�= array('id' => $rows[categoryID], 'parent' => $rows[categoryParentID],'name' => $rows
[categoryName]);
}
if (!isset($category_array[$category_id]))
{
return "";
}
foreach($category_array[$category_id] AS $key=> $category)
{
if ($category['id'] == $default_category)
{
echo "
}else
{
echo "
}
if ($level > 0)
{
echo ">" . str_repeat( "", $level ) . " " . $category['name'] ."\n";
}
else
{
echo ">" . $category['name'] ."\n";
}
Get_Category($key, $level + 1,$default_category);
}
unset($category_array[$category_id]);
}
/*
鍑芥暟杩斿洖鐨勬暟缁勬牸寮忓涓嬫墍绀�:
Array
(
[1] => Array ( [id] => 1 [name] => 涓�绾х被鍒玔level] => 0 [ParentID] => 0 )
[4] => Array ( [id] => 4 [name] => 浜岀骇绫诲埆[level] => 1 [ParentID] => 1 )
[9] => Array ( [id] => 9 [name] => 鍝堝搱[level] => 2 [ParentID] => 4 )
[3] => Array ( [id] => 3 [name] => 浜岀骇绫诲埆[level] => 1 [ParentID] => 1 )
[8] => Array ( [id] => 8 [name] =>aqqqqqd [level] => 2 [ParentID] => 3 )
[2] => Array ( [id] => 2 [name] => 浜岀骇绫诲埆[level] => 1 [ParentID] => 1 )
[7] => Array ( [id] => 7 [name] =>234234 [level] => 2 [ParentID] => 2 )
[6] => Array ( [id] => 6 [name] =>333332 [level] => 2 [ParentID] => 2 )
[5] => Array ( [id] => 5 [name] => 涓夌骇绫诲埆[level] => 2 [ParentID] => 2 )
[10] => Array ( [id] => 10 [name] =>66333666 [level] => 3 [ParentID] => 5 )
)
*/
//鎸囧畾鍒嗙被id,鐒跺悗杩斿洖鏁扮粍
functionCategory_array($category_id = 0,$level=0)
{
global $DB;
$sql = "SELECT * FROM category ORDER BYcategoryID DESC";
$result = $DB->query($sql);
while ($rows = $DB->fetch_array($result))
{
$category_array[$rows['categoryParentID'锛絒$rows['categoryID'锛�= $rows;
}
foreach ($category_array AS $key=>$val)
{
if ($key == $category_id)
{
foreach ($val AS $k=> $v)
{
$options[$k] =
array(
'id' => $v['categoryID'], 'name' =>$v['categoryName'], 'level' => $level, 'ParentID'=>$v['categoryParentID']
);
$children = Category_array($k, $level+1);
if (count($children) > 0)
{
$options = $options + $children;
}
}
}
}
unset($category_array[$category_id]);
return $options;
}
?>
class cate
{
function Get_Category($category_id =0,$level = 0, $default_category = 0)
{
echo $category_id;
$arr = array(
'0' => array(
'1' =>array('id' => 1, 'parent' => 0, 'name' => '1111'),
'2' =>array('id' => 2, 'parent' => 0, 'name' => '2222'),
'4' =>array('id' => 4, 'parent' => 0, 'name' => '4444')
),
'1' => array(
'3' =>array('id' => 3, 'parent' => 1, 'name' => '333333'),
'5' =>array('id' => 5, 'parent' => 1, 'name' => '555555')
),
'3' => array(
'6' =>array('id' => 6, 'parent' => 3, 'name' => '66666'),
'7' =>array('id' => 7, 'parent' => 3, 'name' => '77777')
),
'4' => array(
'8' =>array('id' => 8, 'parent' => 4, 'name' => '8888'),
'9' =>array('id' => 9, 'parent' => 4, 'name' => '9999')
)
);
if (!isset($arr[$category_id]))
{
return "";
}
foreach($arr[$category_id] AS $key=> $cate)
{
if ($cate['id'] ==$default_category)
{
$txt = "
}else{
$txt = "
}
if ($level > 0)
{
$txt1 = ">" .str_repeat( "-", $level ) . " " . $cate['name'] ."\n";
}else{
$txt1 = ">" .$cate['name'] . "\n";
}
$val = $txt.$txt1;
echo $val;
self::Get_Category($key,$level + 1, $default_category);
}
}
function getFlush($category_id =0,$level = 0, $default_category = 0)
{
ob_start();
self::Get_Category($category_id,$level, $default_category);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
}
$id =$_GET['id'];
echo"";
$c = new cate();
//$c->Get_Category();
$ttt=聽 $c->getFlush($id,'0','3');
echo $ttt;
echo"";
?>
钁椾綔鏉冨綊浣滆�呮墍鏈夈�傚晢涓氳浆杞借鑱旂郴浣滆�呰幏寰楁巿鏉冿紝闈炲晢涓氳浆杞借娉ㄦ槑鍑哄銆備簰鑱旂綉+鏃朵唬锛屾椂鍒昏淇濇寔瀛︿範锛屾惡鎵嬪崈閿婸HP,Dream It Possible銆�