µ±Ç°Î»ÖãºLinux½Ì³Ì - Php - Óà PHP ¿ª·¢½¡×³µÄ´úÂë(¶þ):ÓÐЧµØʹÓñäÁ¿

Óà PHP ¿ª·¢½¡×³µÄ´úÂë(¶þ):ÓÐЧµØʹÓñäÁ¿

¡°Óà PHP ¿ª·¢½¡×³µÄ´úÂ롱ÊǹØÓÚ½â¾ö´óÖÐÐÍÓ¦ÓóÌÐòÖеÄʵ¼ÊÎÊÌâµÄϵÁÐÎÄÕ¡£ÔÚ±¾ÎÄÖУ¬PHP ÀÏÊÖ Amol Hatwar ÌÖÂÛÁËÈçºÎÓÐЧµØʹÓñäÁ¿¡£Ëû»¹ÑÝʾÁËÈçºÎͨ¹ýʹÓà PHP ÖпɱäµÄ±äÁ¿ÃûÀ´¹¹ÔìÅäÖÃÎļþ½âÎöÆ÷£¬ÒÔ±ã¼ò»¯½Å±¾ÅäÖá£

ÔÚÎÒµÄǰһƪÎÄÕÂÖУ¬ÎÒÑо¿ÁËÔڹ滮¡¢Éè¼ÆÉõÖÁ±àд´úÂëÆÚ¼ä±ØÐ뿼ÂǵÄһЩÒòËØ¡£ÔÚ±¾ÎÄÖУ¬Äú½«ÕæÕý½Ó´¥µ½Êµ¼Ê´úÂ룬²¢¿ÉÒÔ¿´µ½Êµ¼ÊÔËÐÐÖеÄһЩ¶«Î÷¡£Èç¹ûÄú»¹Ã»Óп´¹ýǰһƪÎÄÕ£¬ÄÇô×îºÃÏÖÔھͿ´Ò»¿´¡£

ÕýÈ·´¦Àí±äÁ¿
±äÁ¿Ó뺯ÊýÊÇÈκμÆËã»úÓïÑԱز»¿ÉÉÙµÄÒªËØ¡£ÓÐÁ˱äÁ¿£¬Äú¿ÉÒÔ½«Êý¾Ý³éÏ󻯣»ÓÐÁ˺¯Êý£¬Äú¿ÉÒÔ½«¼¸ÐдúÂë³éÏ󻯡£ÕýÈç Bruce Eckel ÔÚËûµÄÊé¼®¡¶C++ ±à³Ì˼Ïë¡·ÖÐËù˵µÄÄÇÑù£¬ËùÓбà³ÌÓïÑÔ¶¼Ìṩ³éÏó¡£»ã±àÓïÑÔÊǶԵײã»úÆ÷µÄС³éÏó¡£ËæºóµÄÐí¶àËùνµÄÃüÁîʽÓïÑÔ£¨Èç Fortran¡¢BASIC ºÍ C£©ÊǶԻã±àÓïÑԵijéÏó¡£

±à³ÌÓïÑÔÌṩµÄ³éÏóµÄÖÖÀàºÍÖÊÁ¿Ö±½Ó¹Øϵµ½ÄúËùÄܽâ¾öµÄÎÊÌâµÄ¸´Ôӳ̶ȡ£Àí½â PHP ÈçºÎ´¦Àí±äÁ¿ºÍº¯Êý£¬½«ÓÐÖúÓÚÄúÓÐЧµØʹÓÃËüÃÇ¡£

Ãû³ÆÀïÓÐʲô£¿
¾ÍÏóÎÒÔÚǰһƪÎÄÕÂÖÐÌáµ½µÄÄÇÑù£¬ÃüÃûÔ¼¶¨ºÍ±àÂëÔ¼¶¨ÊÇÖØÒªµÄ¡£ÎÞÂÛÄúʹÓÃʲôÃüÃûÔ¼¶¨£¬Çë¼ÇסҪÔÚÏîÄ¿ÖÐÑϸñ×ñÊØËü¡£Èç¹ûÄúʹÓÃÓ¦ÓõÃ×î¹ã·ºµÄÃüÃûÔ¼¶¨£¬ÄÇôÄúµÄ´úÂ뽫±»¸ü¶àµÄÈËËù½ÓÊÜ¡£

¶Ô±äÁ¿½øÐÐÃüÃûʱ£¬ÔÚ°üÀ¨½Å±¾Ê±ÒªÌرð×¢Òâ²»Òª¸²¸ÇÕýÔÚʹÓõıäÁ¿¡£ÔÚ´óÐÍÓ¦ÓóÌÐòÖУ¬µ±Ôö¼ÓÐµĹ¦ÄÜʱ£¬ÕâÊdz£¼ûµÄ´íÎó¸ùÔ´¡£·ÀÖ¹ÕâÒ»ÎÊÌâµÄ×î¼Ñ°ì·¨¾ÍÊÇʹÓÃǰ׺¡£°Ñ±äÁ¿ËùÔÚÄ£¿éµÄÃû³ÆËõд×÷Ϊǰ׺À´Ê¹Óá£ÀýÈ磬Èç¹ûÒ»¸ö´¦ÀíͶƱµÄÄ£¿éÖÐÓÐÒ»¸ö±£´æÓû§±êʶµÄ±äÁ¿£¬ÄÇôÄú¿ÉÒÔ½«¸Ã±äÁ¿ÃüÃûΪ $poll_userID »ò $pollUserID¡£

Àí½â PHP ±äÁ¿
PHP ÊǽâÊÍÐÍÓïÑÔ¡£ÕâÓÐÐí¶àºÃ´¦£¬ºÜ¿ìÄú½«Ñ§Ï°ÀûÓÃÆäÖеÄһЩ¡£µÚÒ»¸öºÜÃ÷ÏԵĺô¦ÊÇ£ºËüʹÄúÊ¡µôÁËÉè¼Æ-±àÂë-±àÒë-²âÊÔÖÜÆÚ ¡ª ÄúÔڱ༭Æ÷ÖбàдµÄÈκδúÂ붼Á¢¼´¿ÉʹÓá£È»¶ø£¬×îÖØÒªµÄºÃ´¦ÊÇÄú²»Óõ£ÐıäÁ¿µÄÀàÐÍÒÔ¼°ÈçºÎÔÚÄÚ´æÖйÜÀíÕâЩ±äÁ¿¡£ËùÓзÖÅä¸ø½Å±¾µÄÄÚ´æÔÚÖ´ÐÐÍê½Å±¾ºó¶¼ÓÉ PHP ×Ô¶¯Êջء£´ËÍ⣬¿ÉÒÔ¶Ô±äÁ¿Ö´ÐÐÐí¶à²Ù×÷¶ø²»±ØÖªµÀ±äÁ¿µÄÀàÐÍ¡£Çåµ¥ 1 ÖеĴúÂëÔÚ PHP Öй¤×÷Ê®·ÖÕý³££¬µ«ÔÚ C ºÍ Java ÓïÑÔÖлáÅ׳öÒ»´ó¶Ñ´íÎóÏûÏ¢£º

Çåµ¥ 1. ´ø±äÁ¿µÄÑù±¾ PHP ´úÂë


<?php
$myStr = 789696;                       // An integer.
$myVar = 2;                            // Another integer.
$myStr = "This is my favorite band: "; // Strings are more fun.
$myStr = $myStr . "U" . $myVar;        // Doing this is OK, too.
echo "$myVar\n";
?>

°²×°Íê PHP ºó£¬ÈçÒªÔËÐÐÔËÐдúÂ룬¿ÉÊ×ÏȽ«¸Ã´úÂë±£´æΪһ¸ö .php Îļþ£¬ÔÙ½«¸ÃÎļþ·ÅÖÃÔÚ Web ·þÎñÆ÷ÉÏ£¬È»ºó½«ä¯ÀÀÆ÷Ö¸Ïò¸ÃÎļþ¡£¸üºÃµÄ°ì·¨ÊÇ°²×° PHP µÄ CGI °æ±¾¡£È»ºó£¬Í¨¹ýÔÚ shell »òÃüÁîÌáʾ·ûÏÂÊäÈëÒÔÏÂÃüÁ²¢Óðüº¬ÄúµÄ½Å±¾µÄÎļþÃûÌæ´ú script-name£¬ÕâÑù¾Í¿ÉÒÔÔËÐиýű¾ÁË¡£

path-to-php/php script-name

¸Ã´úÂëÄܹ»Õý³£¹¤×÷£¬ÒòΪ PHP ÊÇÀàÐÍ¿íËɵÄÓïÑÔ¡£ÓÃͨË×Ò׶®µÄÓ¢Ó¿ÉÒÔ²»¿¼ÂDZäÁ¿ÀàÐÍ£¬¿ÉÒÔ°Ñ×Ö·û´®¸³Öµ¸øÕûÊý£¬ÒÔ¼°ºÁ²»·ÑÁ¦µØÓýϴóµÄ×Ö·û´®Ìæ´ú½ÏСµÄ×Ö·û´®¡£ÕâÔÚÏó C ÕâÑùµÄÓïÑÔÖÐÊDz»¿ÉÄܵÄÊÂÇé¡£ÔÚÄÚ²¿£¬PHP ½«±äÁ¿ËùÓµÓеÄÊý¾ÝÓëÀàÐÍ·Ö¿ª´æ´¢¡£ÀàÐÍ´æ´¢ÔÚµ¥¶ÀµÄ±íÖС£Ã¿µ±³öÏÖ°üº¬²»Í¬ÀàÐ͵ıí´ïʽʱ£¬PHP ×Ô¶¯È·¶¨³ÌÐòÔ±ÏëÒª×öʲô£¬½Óןü¸Ä±íÖеÄÀàÐÍ£¬È»ºó×Ô¶¯¶Ô±í´ïʽÇóÖµ¡£

½éÉÜÒ»¸ö³£¼ûµÄСÎÊÌâ
²»Óõ£ÐÄÀàÐ͹ÌÈ»ºÜºÃ£¬µ«ÓÐʱÄÇÒ²»áʹÄúÏÝÈëÕæÕýµÄÂé·³¡£Ôõô»ØÊÂÄØ£¿ÕâÀïÓÐÒ»¸öʵ¼ÊµÄʾÀý£ºÎÒ³£³£±ØÐë°ÑÔÚ»ùÓÚ Windows µÄ PC ÉÏ´´½¨µÄÄÚÈÝÒƵ½ Linux ϵͳ£¬ÒÔ±ãÄÜÔÚ Web ÉÏʹÓÃËüÃÇ¡£»ùÓÚ Windows µÄÎļþϵͳÔÚ´¦ÀíÎļþÃûʱÊDz»Çø·Ö´óСдµÄ¡£ÎļþÃû DefParser.php ºÍ defparser.php Ö¸Ïò Windows ÉϵÄͬһÎļþ¡£ÔÚ Linux ²Ù×÷ϵͳÉÏ£¬ËüÃÇÖ¸Ïò²»Í¬µÄÎļþ¡£Äú¿ÉÄÜÌᳫÎļþÃûҪôȫÓôóд£¬ÒªÃ´È«ÓÃСд£¬µ«×îºÃµÄ×ö·¨Ó¦¸ÃÊÇʹ´óСд±£³Ö²»±ä¡£

½â¾öÕâ¸öСÎÊÌâ
¼ÙÉèÄúÏëÒªÒ»¸öº¯Êý£¬ËüÄÜÔÚ²»¿¼ÂÇ´óСдµÄÇé¿öϼì²é¸ø¶¨ÎļþÊÇ·ñ´æÔÚÓÚij¸öĿ¼ÖС£Ê×ÏÈ£¬½«Õâ¸öÈÎÎñ·Ö½â³ÉһЩ¼òµ¥µÄ²½Öè¡£·Ö½â´úÂë¿ÉÄÜÌýÆðÀ´ÓÐЩ¿ÉЦ£¬µ«ËüȷʵÓÐÖúÓÚÄúÔÚ±àд´úÂëʱ½«Ö÷Òª¾«Á¦·ÅÔÚÕâ¶Î´úÂëÉÏ¡£ÁíÍ⣬ÔÚÖ½ÉÏÖØд²½ÖèʼÖÕ±ÈÖØд´úÂëÈÝÒ׵öࣺ

  1. »ñȡԴĿ¼ÖеÄËùÓÐÎļþÃû
  2. ¹ýÂ˵ô . ºÍ .. Ŀ¼
  3. ¼ì²éÄ¿±êÎļþÊÇ·ñ´æÔÚÓÚ¸ÃĿ¼ÖÐ
  4. Èç¹ûÎļþ´æÔÚ£¬Ôò»ñÈ¡¾ßÓÐÕýÈ·´óСдµÄÎļþÃû
  5. Èç¹ûÃû³Æ²»Æ¥Å䣬Ôò·µ»Ø false

Òª¶ÁȡĿ¼µÄÄÚÈÝ£¬ÐèҪʹÓà readdir() º¯Êý¡£¿ÉÒÔÔÚ PHP ÊֲᣨÇë²ÎÔIJο¼×ÊÁÏ£©ÖлñÈ¡Óйظú¯ÊýµÄ¸ü¶àϸ½Ú¡£ÖÁÓÚÏÖÔÚ£¬Ö»ÒªÖªµÀ£ºreaddir() ÔÚÿ´Îµ÷ÓÃʱ»áÖð¸ö·µ»Ø¸ø¶¨Ä¿Â¼ÖÐËùÓÐÎļþµÄÃû³Æ¡£ÔÚÁгöÁËËùÓеÄÎļþÃûºó£¬Ëü·µ»Ø false¡£Äú½«Ê¹ÓÃÒ»¸öÑ­»·£¬¸ÃÑ­»·ÔÚ readdir() ·µ»Ø false ʱÖÕÖ¹¡£

µ«ÕâÑù¾Í¹»ÁËÂð£¿Çë¼Çס£¬PHP ÊÇÀàÐÍ¿íËɵÄÓïÑÔ£¬ÕâÒâζׯὫÕûÐÍÖµ 0 Óë false ÊÓΪÏàͬ£¨ÉõÖÁ C Ò²°Ñ 0 ºÍ²¼¶ûÖµ false ÊÓΪµÈ¼Û£©¡£ÎÊÌâ²»ÊǸôúÂëÊÇ·ñÄÜÕý³£¹¤×÷£»ÏëÏóһϣ¬Èç¹ûÎļþµÄÃû³ÆÊÇ 0 »áÈçºÎ£¡¸Ã½Å±¾»á¹ýÔçÖÕÖ¹¡£¿ÉÒÔʹÓÃÒÔϽű¾£¨Çåµ¥ 2£©À´È·¶¨ 0 Óë²¼¶ûÖµ false µÄµÈ¼ÛÐÔ£º

Çåµ¥ 2. È·¶¨ 0 Óë²¼¶ûÖµ false ÊÇ·ñµÈ¼ÛµÄ½Å±¾


<?php
$file_name = 0;
if (0 == $file_name ) {
echo "The code is in trouble ...\n";  // This text prints on the screen.
}

else {
echo "Phew ... The code is safe";   // This text never prints.
}
?>

ÄÇôÄú¿ÉÒÔ×öʲôÄØ£¿ÄúÖªµÀ PHP »áÔÚÄÚ²¿´æ´¢ÀàÐÍ£¬¶øÈç¹ûÄܹ»·ÃÎÊÕâЩÀàÐ͵Ļ°£¬ÎÊÌâ¾Í½â¾öÁË¡£²¼¶ûÖµ false ºÍÕûÐÍÖµ 0 Ã÷ÏÔÊDz»Í¬µÄ¡£

PHP ÓÐÒ»¸ö gettype() º¯Êý£¬µ«ÈÃÎÒÃÇÔÚÕâÀïÑ¡Ôñ¸ü¼òµ¥µÄ·½·¨¡£Äú¿ÉÒÔʹÓà === ÔËËã·û£¨Êǵģ¬ÓÐÈý¸öµÈºÅ£©¡£²»Í¬Ö®´¦ÔÚÓÚ¸ÃÔËËã·ûͬʱ±È½ÏÊý¾ÝµÄÖµºÍÀàÐÍ¡£Èç¹ûÄú¶Ô´Ë¾õµÃÓÐЩÒÉ»ó£¬PHP »¹ÓÐ !== ÔËËã·û¡£Ö»ÓÐ PHP 4 ÖвÅÓÐÕâЩÐÂÐÍÔËËã·ûºÍ gettype() º¯Êý¡£Çåµ¥ 3 ÏÔʾÁ˽â¾ö¸ÃÎÊÌâµÄÍêÕû´úÂ룺

Çåµ¥ 3. ÍêÕû´úÂë


<?php
/* This is the function where the action takes place */
function chk_file_name( $name, $path="." ) {
	$fileList = get_file_list($path);
	foreach ($fileList as $file) {
		if (eregi($name, $file)) {
			return $file;
		}
	}
return false;
}

/* Return the list of files in a given directory in an array. 
    Uses the current directory as default. */
function get_file_list($dirName=".") {
	$list = array();
	$handle = opendir($dirName);
	while (false !== ($file = readdir($handle))) {

	/* Omit the '.' and the '..' directories. */
		if ((".."== $file) || ("."== $file)) continue;
		array_push($list, $file);
	}
	
	closedir($handle);
	return $list;
}

?>

¹Û²ìÖеõ½µÄ¾­Ñé
ÎÒ²»´òËã¶ÔÇåµ¥ 3 Öи÷¸öº¯ÊýµÄ¹¦ÄܼÓÒÔ˵Ã÷£¬Ïà·´£¬ÎÒ¹ÄÀøÄú²éÔÄ PHP ÊֲᣨÇë²ÎÔIJο¼×ÊÁÏ£©¡£µ±ÄúʹÓò»ÊìϤµÄº¯Êýʱ£¬¼ÙÉèµÄ²ÎÊýÓë·µ»ØÖµµÄÀàÐÍ»áÊÇÁíÒ»¸ö´íÎó¸ùÔ´¡£ÎÒûÓÐ¶Ô PHP ÖеÄÄÚÖú¯Êý¼ÓÒÔ˵Ã÷£¬¶øÊÇ´òËã˵Ã÷һЩ²»Ì«Ò»Ä¿ÁËÈ»µÄÊÂÇé¡£

µ±ÖÕÖ¹Ìõ¼þÖÐÉæ¼°²»Í¬µÄ±äÁ¿ÀàÐÍʱ£¬Í¨¹ýʹÓà === ºÍ !== ÔËËã·û½øÐÐÇ¿ÀàÐͼì²éÊǺÜÖØÒªµÄ¡£

Óɸ÷²¿·Ö×é³ÉµÄ´úÂë
ÎÒ±¾À´¿ÉÒÔ½«Õû¸ö½Å±¾±àдΪһ¸öº¯Êý£¬µ«ÕâÀïÎÒÈ´°Ñ´úÂë·Ö¸î³ÉÁ½¸öº¯Êý¡£»¹¼ÇµÃǰһƪÎÄÕÂÖеġ°·Ö¶øÖÎÖ®¡±¹æÔòÂð£¿ÎÒÕâô×öÕýÊÇÒòΪÿ¸öº¯ÊýËùÆðµÄ×÷Óò»Í¬¡£Èç¹ûÄúÓÃÆäËü½Å±¾»ñȡij¸öĿ¼µÄÄÚÈÝ£¬ÄÇôÏÖÔھͿÉÒÔʹÓ÷½±ãµÄʵÏÖ¡£ÎÒÏ£ÍûÄú¿¼ÂÇһЩÊÂÇ飺ÏëÏóһϽ«Õû¸ö½Å±¾×÷Ϊһ¸öº¯ÊýÀ´ÊµÏÖ£¬È»ºóÏëÏóµ÷ÊÔ¡¢²âÊÔºÍÖØÓôúÂëËùÐèµÄ¹¤×÷¡£

ÕýȷʹÓÃÑ­»·
ÏÖÔÚ¿´¿´ foreach Ñ­»·£¬ÏëÏëΪʲô²»Óà for Ñ­»·£¿Ê¹Óà for Ñ­»·ÒªÇóÄúÖªµÀÊý×éÖÐÏîµÄÊýÄ¿ ¡ª ÐèÒªÒ»¸ö¶îÍâµÄ²½Öè¡£´ËÍ⣬ÔÚ´¦Àí PHP Êý×éʱ£¬ÓпÉÄܳ¬³öÊý×é±ß½ç¡£Ò²¾ÍÊÇ˵£¬ÔÚÊý×éÖ»ÓÐ 10 ¸öÔªËØʱ£¬ÊÔͼ·ÃÎÊËüµÄµÚ 15 ¸öÔªËØ¡£PHP µÄÈ·»á¸ø³öÒ»¸öС¾¯¸æ£¬µ«¾ÝÎÒËùÖª£¬ÔÚһЩÇé¿öÏ£¬µ±·´¸´ÔËÐÐij¸ö½Å±¾Ê±£¬CPU »î¶¯ÂÊ»áͻȻÉÏÉýµ½ 100% ¶ø·þÎñÆ÷ÐÔÄÜÔòÁ¬ÐøϽµ¡£ÎÒ½¨ÒéÄú¾¡¿ÉÄܵرÜÃâʹÓà for Ñ­»·¡£

¶ÏÑÔÐ﵀ if
×îºó£¬ÎÒÏ£ÍûÄúÑо¿Ò»ÏÂÄǸöÔÚ get_file_list() º¯ÊýÖÐÓÃÓÚºöÂÔ . ºÍ .. Ŀ¼µÄ½Ï´óµÄ if Ìõ¼þ¡£ÏÔÈ»£¬ÎÒ¿ÉÒÔ²ÉÓô«Í³µÄ·½·¨£¬¸ù¾Ý³£ÊýÀ´¼ì²é±äÁ¿¡£µ«ÔÚÎÒ×Ô¼ºµÄÐí¶à±àÂë»èÕÐÖУ¬ÎÒ¾­³£»áÒÅ©µÈºÅ²¢ÇÒÔÚÒÔºóÕÒ²»µ½ÄÄÀï³öÁËÎÊÌâ¡£µ±È»£¬PHP ²»»á±¨´í£¬ÒòΪËüÈÏΪÎÒÏë½øÐи³Öµ¶ø²»ÊDZȽϡ£µ±Äú¸ù¾Ý±äÁ¿À´±È½Ï³£Êý²¢ÇÒÓÖÒÅ©ÁËÒ»¸öµÈºÅʱ£¬PHP »áÅ׳ö´íÎóÏûÏ¢¡£

¿É±äµÄ±äÁ¿Ãû
ÏÖÔÚÀ´ÌÖÂÛһЩÆæÃîµÄÊÂÇé¡£×÷ΪÐÂÊֵĿª·¢ÈËÔ±ÈÏΪ£¬Ê¹Óÿɱä±äÁ¿À´Íê³ÉÈÎÎñÊÇÒ»ÖÖÁîÈ˷ѽâµÄ·½·¨£¬ËùÒÔ³£³£»Ø±ÜËü¡£Êµ¼ÊÉÏ£¬ºÜÈÝÒ×Àí½âºÍʹÓÿɱä±äÁ¿¡£ËüÃÇÒѾ­²»Ö¹Ò»´ÎµØ°ïÎÒ°ÚÍÑÀ§¾³£¬¶øÇÒËüÃÇÊÇÒ»ÖÖÖØÒªµÄÓïÑÔÔªËØ¡£ÊÂʵÉÏ£¬ÔÚÓÐЩÇé¿öÏ£¬Ê¹Óÿɱä±äÁ¿ÔÚËùÄÑÃâ¡£ºÜ¿ìÎÒ½«Ñо¿Ò»ÖÖ´ËÀàÏÖʵÇé¿ö£¬µ«Ê×ÏÈÈÃÎÒÃÇ¿´¿´¿É±ä±äÁ¿µ½µ×ÊÇʲô¡£ÈÃÎÒÃÇÏȳ¢ÊÔÒ»ÏÂÇåµ¥ 4 ÖеĴúÂ룺

Çåµ¥ 4. ¾ßÓпɱä±äÁ¿µÄ´úÂë


<?php
$myStr = "I";
$$myStr  = "am";
$$$myStr = "great.";

// These are new variables.
echo "$myStr ";
echo "$I ";
echo "$am\n";

// Now for the moment of truth ...";

$am = "exaggerating.";

// Does it work the other way?
echo "$myStr ";
echo "${$myStr} ";
echo "${${$myStr}}\n ";
?>

Ê×ÏÈ£¬Çåµ¥ 4 ÖеĴúÂëÉùÃ÷ÁËÃûΪ $myStr µÄ±äÁ¿£¬²¢½«×Ö·û´® I ¸³¸øËü¡£½ÓÏÂÀ´µÄÓï¾ä¶¨ÒåÁËÁíÒ»¸ö±äÁ¿¡£µ«Õâ´Î£¬±äÁ¿µÄÃû³ÆÊÇ $myStr ÖеÄÊý¾Ý¡£$$myStr ÊÇÒ»ÖÖ¸æËß PHP ²úÉúÁíÒ»¸ö±äÁ¿µÄ·½·¨£¬ÆäÒâ˼ÊÇ¡°ÎÒÏëÒªÒ»¸ö±äÁ¿£¬¿ÉÒÔÔÚ±äÁ¿ $myStr ÖÐÕÒµ½Õâ¸ö±äÁ¿µÄÃû³Æ¡±¡£µ±È»£¬Îª×öµ½ÕâÒ»µã£¬±ØÐ붨Òå $myStr¡£ËùÒÔ£¬ÏÖÔÚÄúÓÐÒ»¸öÃûΪ I µÄ±äÁ¿£¬²¢ÓÃ×Ö·û´® am ¸øËü¸³Öµ¡£½ÓÏÂÀ´µÄÓï¾ä×öÁËͬÑùµÄÊÂÇ飬²¢½«×Ö·û´® great ¸³¸øÃûΪ am µÄ±äÁ¿¡£¶ø am Ö»ÊDZäÁ¿ I ÖеÄÊý¾Ý¡£

ÄdzÎÇåÁËһЩÊ£¬µ« echo Óï¾äÖÐÄÇЩÆæ¹ÖµÄ»¨À¨ºÅÊÇÔõô»ØÊÂÄØ£¿ÄǾÍÊÇÄú´òÓ¡¿É±ä±äÁ¿µÄ·½·¨¡£Èç¹ûÄúÊ¡ÂÔ»¨À¨ºÅ£¬ÄÇô PHP ÔÚ´òӡʱ»á½«ÃÀÔª·ûºÅ£¨$£©¸½¼Óµ½±äÁ¿µÄÄÚÈÝÉÏ¡£ÕâЩ»¨À¨ºÅ¸æËß PHP Ê×ÏȶÔËüÃÇÀïÃæµÄ±äÁ¿ÇóÖµ¡£

ÊÔ×ÅÕâÑù¿¼ÂÇ£º±äÁ¿¿ÉÒÔ×öʲô£¿¼òµ¥µØ˵£¬ËüÃdzéÏó»ò±íʾÊý¾Ý£¬ÕâЩÊý¾Ý¿ÉÒԱ仯£¬¶øËüÃǵÄÃû³Æ±£³Ö²»±ä¡£¿É±ä±äÁ¿×öµÄÊÇͬÑùµÄÊÂÇ飻ËüÃdzéÏóÊý¾Ý¡£µ«ÔÚ±¾ÀýÖУ¬ËüÃÇ°üº¬µÄÊý¾Ýʵ¼ÊÉÏÊÇÁíÒ»¸ö±äÁ¿µÄÃû³Æ¡£

ÎÒÔÚÇåµ¥ 4 ÖÐËù¸øµÄÀý×ÓÊÇΪÁËÈÃÄúÊìϤ¿É±ä±äÁ¿¡£¿É±ä±äÁ¿ÃûµÄʵ¼Ê¹¦ÄÜÀ´×ÔÕâÑùµÄÊÂʵ£ºÄú¿ÉÒÔÔÚÔËÐÐʱ¶¯Ì¬µØÉú³É¿É±äµÄ±äÁ¿Ãû¡£Äú½«ÔÚ¹¹ÔìÒ»¸öÅäÖÃÎļþ½âÎöÆ÷ʱÓõ½ÕâÒ»ÌØÐÔ¡£

ÅäÖÃÎļþ½âÎöÆ÷
°´ÕÕÎҵľ­Ñ飬ÔÚÅäÖÃÓ¦ÓóÌÐòÒÔʹÆäÔËÐÐÆڼ䣬Óà PHP ±à¼­ÅäÖÃÎļþʱ£¬Óû§³£ÓÐËù±§Ô¹¡£ÅäÖÃÖ»²»¹ýÊÇÈ«¾Ö±äÁ¿µÄÒ»¸öÁÐ±í£¬Ó¦ÓóÌÐòÖеÄÆäËü½Å±¾ÒÀ¿¿ËüÀ´²éÕÒÎļþ¡¢URL ºÍÆäËü¿ØÖÆÓ¦ÓóÌÐòÐÐΪµÄÉèÖá£Ò»¸öÒÅ©µÄÃÀÔª·ûºÅ¡¢·ÖºÅ»òÒ»¶Îδ·â±ÕµÄ×¢Êͳ£³£»áÆÆ»µÕû¸ö´úÂë¡£ÓÐʲôÄÜ°ïÖúÓû§ÄØ£¿

¼ÙÉèÄú¸øÓû§Ò»¸öÎļþ£¬ÈÃÓû§Ê¹ÓÃÓɵȺŷֿªµÄ¼òµ¥µÄÃû³Æ-Öµ¶ÔÀ´±à¼­¸ÃÎļþ¡£ÅäÖÃÎļþÀàËÆÓÚÇåµ¥ 5¡£ÒÔ # ¿ªÍ·µÄÐеÄÎı¾±»×÷ΪעÊÍ´¦Àí¡£

Çåµ¥ 5. Ñù±¾ÅäÖÃÎļþ


# This is sample a configuration file.
admin_fname = Amol
admin_lname = Hatwar
admin_email = [email protected]
admin_login = admin
admin_pass = secretstring
# File Ends

Òâ˼Çå³þÂð£¿Êǵģ¬µÄÈ·Èç´Ë¡­¡­¼ÈÈ»¿ÉÒÔÓà PHP ½âÎöÎļþ£¬ÎªÊ²Ã´ÈÃÓû§±à¼­ÅäÖÃÎļþÄØ£¿ÊÂʵÉÏ£¬ÕâÊÇÈËÃǷdz£ÆÚÍûµÄ¡£Çë¼Çס£¬ÄúµÄÓ¦ÓóÌÐò±ØÐëÔÚ¶ÔÓû§Òþ²ØËùÓи´ÔÓÐÔµÄͬʱ£¬ÈÔÈ»ÈÃËûÖªµÀËûÄÜ¿ØÖƸÃÓ¦ÓóÌÐò¡£

Äú¿ÉÒÔ±àд¸ºÔð½âÎö¹¤×÷µÄº¯Êý£¬ÕâÑùÄú¿ÉÒÔÔÚÈκεط½Ê¹ÓÃËü¶ø²»ÓÃ×öÈκÎÐ޸ġ£ÈÃÎÒÃǽ«¸ÃÈÎÎñ·ÖΪһЩ¸ü¼òµ¥µÄ²½Ö裺

  1. ÖðÐеضÁÈ¡Îļþ
  2. ¶ªÆúÒ»ÐÐÖÐ # ºÅ×Ö·ûºóµÄËùÓÐÄÚÈÝ
  3. ÒԵȺÅΪ½ç£¬½«Ò»ÐзÖΪÁ½¸ö×Ö·û´®£¬²¢¶ªÆúµÈºÅ
  4. ³ýÈ¥×Ö·û´®ÖеĶîÍâ¿Õ¸ñ
  5. ÏàÓ¦ÉùÃ÷±äÁ¿

Òª±àд×îºóÒ»²½£¬Ö»ÓÐʹÓÿɱä±äÁ¿²ÅÐС£Çåµ¥ 6 ÏÔʾÁË´úÂ룺

Çåµ¥ 6. ½âÎöº¯Êý


<?php
/* conf_parser.php */

/* Give the filename with path info whenever possible. */
function conf_parse($file_name) {

// @ in front makes the function quiet. Error messages are not printed.
$fp = @fopen($file_name, "r") or die("Cannot open $file_name");

while ($conf_line = @fgets($fp, 1024)) {
$line = ereg_replace("#.*$", "", $line);   // Do stripping after hashes.
if ($line == "") continue;   // Drop blank lines resulting from the previous step.
list($name, $value) = explode ('=', $line);   // Drop '=' and split.
$name = trim($name);   //  Strip spaces.
$$name= trim($value);   // Define the said variable.  
}
fclose($fp) or die("Can't close file $file_name");
}
?>

ÓÃÕýÔò±í´ïʽ³ýÈ¥ # ºÅ¡£¾¡¹ÜÕâÀïµÄ±í´ïʽºÜ¼òµ¥£¬µ«ÒªÖªµÀ¸´ÔÓµÄÕýÔò±í´ïʽ»áÏûºÄ´óÁ¿µÄ CPU ʱ¼ä¡£´ËÍ⣬Ϊÿҳ·´¸´µØ½âÎöÅäÖÃÎļþ²»ÊÇÒ»¸öºÃµÄ¾ö²ß¡£¸üºÃµÄÑ¡ÔñÊÇ£ºÊ¹ÓñäÁ¿»ò¶¨ÒåÓï¾ä½«ÒѽâÎöµÄÊä³ö´æ´¢Îª PHP ½Å±¾¡£ÎÒÇãÏòÓÚʹÓà define() º¯Êý½øÐж¨Ò壬ÒòΪһµ©ÉèÖÃÁËÖµ¾Í²»ÄÜÔÚÔËÐÐʱ¸ü¸ÄËü¡£¿ÉÒÔÔڲο¼×ÊÁÏÖÐÕÒµ½Ò»¸öÄܹ»¸ù¾ÝÄúµÄÐèÒª¼ÓÒÔÐ޸ĵÄʵÏÖ¡£

½áÊøÓï
¼ÈȻ֪µÀÁËÈçºÎÓÐЧµØʹÓñäÁ¿£¬ÄÇôÄú¿ÉÒÔ×ÅÊÖ±àдһЩ½Ï´óµÄ³ÌÐòÁË¡£ÔÚ±¾ÏµÁеÄÏÂһƪÎÄÕÂÖУ¬ÎÒ½«Ñо¿º¯ÊýºÍ API Éè¼Æ¡£ÔÚÏ´μûÃæÒÔÇ°£¬Ï£ÍûÄú±à³ÌÓä¿ì£¡

²Î¿¼×ÊÁÏ

  • ÏÂÔØ def_parser.zip Îļþ£¬ÆäÖаüº¬ÅäÖÃÎļþ½âÎöÆ÷µÄʵÏÖ£¬Äú¿ÉÒÔ½«¸Ã½âÎöÆ÷дµÄÎļþ°üÀ¨ÔÚÄúµÄ½Å±¾ÖС£

  • Çë·ÃÎÊ PHPBuilder.com ºÍ Developer Shed£¬ÒÔ»ñÈ¡¸ü¶àÓйØÔÚ PHP ÖÐʹÓÿɱä±äÁ¿Ãû³ÆµÄʾÀý¡£

  • ÇëÔĶÁÁ˽â Free Energy£¬ÕâÊÇÒ»¸ö¶Ô Web Ó¦ÓóÌÐò½øÐбàÂëµÄ¼òµ¥·½·¨¡£

  • ÏÂÔØ»òÔÚÏß²éÔÄ PHP Êֲᡣ

  • ²Î¼Ó¡°Writing efficient PHP¡±½Ì³Ì£¬Ñ§Ï°ÈçºÎ±àдÓÐЧµÄ PHP ´úÂ루developerWorks£¬2002 Äê 7 Ô£©¡£

  • ÇëÔĶÁ±¾ÏµÁÐÎÄÕÂÖеĵÚһƪ¡°µì¶¨»ù´¡¡±£¬Á˽âÓйØÉè¼ÆºÍ¹æ»® Web Ó¦ÓóÌÐòµÄÒªµã£¨developerWorks£¬2002 Äê 8 Ô£©¡£

¹ØÓÚ×÷Õß
Amol Hatwar ´ÓÄܼÇÊÂÆð¾Í¿ªÊ¼½Ó´¥¼ÆËã»ú¡£×÷Ϊ GNU/Linux µÄ¾ø¶ÔÓµ»¤Õߣ¬ËûΪ¹ýÈ¥ÔÚ Microsoft ƽ̨Éϱà³Ì¸Ðµ½ÄھΡ£ËûÏÖÔÚ×÷Ϊ¶ÀÁ¢¹ËÎÊ°ïÖúÖڶ๫˾ǨÒƵ½ GNU/Linux¡£×÷Ϊ¿ª·¢ Web Ó¦ÓóÌÐòÁìÓòµÄר¼Ò£¬Ëû°ÑËùÊ£ÎÞ¼¸µÄ¿ÕÓàʱ¼ä»¨ÔÚÑо¿Ã»ÈËÌý˵¹ýµÄ¼¼ÊõÉÏ¡£ËûÏÖÔÚµÄÐËȤ°üÀ¨¿ª·ÅÔ´ÂëÈí¼þ¡¢Web ·þÎñ¡¢¶ÔµÈ¼ÆËãÒÔ¼°¸ß¿ÉÓÃÐÔȺ¼¯¡£Äú¿ÉÒÔͨ¹ý
[email protected] Óë Amol ÁªÏµ¡£