һƪ²»´íµÄPHP»ù´¡Ñ§Ï°±Ê¼Ç

5年以前  |  阅读数:415 次  |  编程语言:PHP 

1¡¢ PHPƬ¶ÎËÄÖÖ±iʾÐÎʽ¡£
±e×¼tags£º<?php ?>
short tags£º<? ?> ÐeÒªÔÚphp.iniÖÐÉeÖÃshort _open_tag=on£¬Ä¬ÈÏÊÇon
asp tags£º <% %>ÐeÒªÔÚphp.iniÖÐÉeÖÃasp_tags=on£¬Ä¬ÈÏÊÇoff
script tags£º
2¡¢ PHP±aÁ¿¼°Êý¾ÝÀaÐÍ

  1.    $variable  £¬±aÁ¿ÒÔ×Öĸ¡¢_¿ªÊ¼£¬²»ÄÜÓпոñ   
  2. ¸³Öµ$variable=value;
  3. ÈoÀaÐÍ£¬Ö±½Ó¸³Öµ£¬²»ÐeÒªÏÔʾÉuÃ÷Êý¾ÝÀaÐÍ
  4. »u±¾Êý¾ÝÀaÐÍ£ºInteger£¬Double,String,Boolean,Object£¨¶ÔÏo»oÀa£(C),Array(Êý×e)
  5. ÌØÊaÊý¾ÝÀaÐÍ£ºResourse£¨¶ÔµÚÈý½×ÊÔ´£¨ÈçÊý¾Ý¿a£(C)µÄÒýÓã(C)£¬Null£¨¿Õ£¬Î´³oʼ»¯µÄ±aÁ¿£(C)
    3¡¢ ²Ù×÷
    u
  6. ¸³Öµ²Ù×÷*u£º=
  7. ËaÊo²Ù×÷u£º+£¬-£¬£¬/£¬%£¨È¡Ä££(C)
  8. Á¬½Ó²Ù×÷u£º. £¬ÎÞÂÛ²Ù×÷ÊýÊÇʲô£¬¶¼µ±³ÉString£¬½a¹uµ»ØString
  9. Combined Assignment OperatorsºÏ¼Æ¸³Öµ²Ù×÷u£º+=£¬=£¬/=£¬-=£¬%=£¬.=
  10. Automatically Incrementing and Decrementing×Ô¶¯Ôo¼o²Ù×÷*u£º
    £¨1£(C)$variable+=1 <=>$variable++£»$variable-=1 <=>$variable-,¸ucÓiÑÔÒ»Ñu£¬ÏÈ×oÆaËu²Ù×÷£¬ºo++»o-
    £¨2£(C)++$variable£¬-$variable£¬ÏÈ++»o-£¬ÔÙ×oÆaËu²Ù×÷
  11. ±È½Ï²Ù×÷*u£º= =£¨×o±ßµÈÓÚÓұߣ(C)£¬£¡=£¨×o±ß²»µÈÓÚÓұߣ(C)£¬= = =£¨×o±ßµÈÓÚÓұߣ¬ÇÒÊý¾ÝÀaÐÍÏaͬ£(C)£¬>=£¬>£¬<£¬<=
  12. Âß¼­²Ù×÷u£º|| ¨® or£¬&&¨®and£¬xor(µ±×oÓÒÁ½±ßÓÐÇÒÖ»ÓÐÒ»¸oÊÇtrue£¬µ»Øtrue)£¬!
    4¡¢ ×¢ÊÍ£º
    µ¥ÐÐ×¢ÊÍ£º// £¬#
    ¶aÐÐ×¢ÊÍ£º/ /
    5¡¢ ÿ¸oÓi¾aÒÔ;ºÅ½a⣬ÓejavaÏaͬ
    6¡¢ ¶¨Òa³£Á¿£ºdefine(¡°CONSTANS_NAME¡±,value)
    7¡¢ ´oÓ¡Ói¾a£ºprint,ÓecÓiÑÔÏaͬ
    8¡¢ Á÷³Ì¿ØÖÆÓi¾a
  13. ifÓi¾a£º
    £¨1£(C)if(expression)
    {
    //code to excute if expression evaluates to true
    }
    £¨2£(C)if(expression)
    {
    }
    else
    {
    }
    (3)if(expression1)
    {
    }
    elseif(expression2)
    {
    }
    else
    {
    }
  14. swichÓi¾a
    switch ( expression )
    {
    case result
    // execute this if expression results in result1
    break;
    case result
    // execute this if expression results in result2
    break;
    default:
    // execute this if no break statement
    // has been encountered hitherto
    }
  15. £¿²Ù×÷*u£º
    ( expression )?returned_if_expression_is_true:returned_if_expression_is_false;
  16. whileÓi¾a£º
    £¨1£(C) while ( expression )
    {
    // do something
    }
    £¨2£(C)do
    {
    // code to be executed
    } while ( expression );
  17. forÓi¾a£º
    for ( initialization expression; test expression; modification expression ) {
    // code to be executed
    }
  18. break£»continue
    9¡¢ ±aдº¯Êý
  19. ¶¨Òaº¯Êý£º
    function function_name($argument1,$argument2,¡­¡­) //ÐβÎ
    {
    //function code here;
    }
  20. º¯Êýµ÷ÓÃ
    function_name($argument1,$argument2,¡­¡­); //ÐβÎ
  21. ¶¯Ì¬º¯Êýµ÷Óã¨Dynamic Function Calls£(C)£º Listing 6.5 "; } $function_holder = "sayHello"; //½«º¯ÊýÃu¸³Öµ¸ø±aÁ¿$function_holder $function_holder(); //±aÁ¿$function_holder³ÉΪº¯ÊýsayHelloµÄÒýÓ㬵÷ÓÃ$function_holder()Ïaµ±ÓÚµ÷ÓÃsayHello ?>
  22. ±aÁ¿×÷ÓÃÓo£º
    È«¾Ö±aÁ¿£º Listing 6.8 "; } meaningOfLife(); ?>
  23. ʹÓÃstatic Listing 6.10 $num_of_calls. $txt"; } numberedHeading("Widgets"); //µÚÒ»´Îµ÷ÓÃʱ£¬´oÓ¡$num_of_callsֵΪ1 print("We build a fine range of widgets

    "); numberedHeading("Doodads"); /*µÚÒ»´Îµ÷ÓÃʱ£¬´oÓ¡$num_of_callsֵΪ2£¬ÒoΪ±aÁ¿ÊÇstaticÐ͵ģ¬staticÐÍÊdz£×¤ÄÚ´aeµÄ*/ print("Finest in the world

    "); ?>

  24. ´«Öµ£¨value£(C)ºÍ´«Ö*£¨reference£(C)£º
    ´«Öµ£ºfunction function_name($argument) Listing 6.13 ½a¹u£º10 ´«Ö*£ºfunciton function_name(&$argument) Listing 6.14 ½a¹u£º15
  25. ´´½¨ÄaÃuº¯Êý£ºcreate_function(¡®string1','string2'); create_functionÊÇPHPÄÚ½¨º¯Êý£¬×¨ÃÅÓÃÓÚ´´½¨ÄaÃuº¯Êý£¬½ÓÊÜÁ½¸ostringÐͲÎÊý£¬µÚÒ»¸oÊDzÎÊýÁбi£¬µÚ¶þ¸oÊǺ¯ÊýµÄÖ÷Ìa Listing 6.15
  26. ÅжϺ¯ÊýÊÇ*ñ´aeÔÚ£ºfunction_exists(function_name),²ÎÊýΪº¯ÊýÃu
    10¡¢ ÓÃPHPÁ¬½ÓMySQL
  27. Á¬½Ó£º&conn;=mysql_connect("localhost", "joeuser", "somepass");
  28. ¹Ø±ÕÁ¬½Ó£ºmysql_close($conn);
    3£(C) Êý¾Ý¿aÓeÁ¬½Ó½¨Á¢ÁªÏµ£ºmysql_select_db(database name, connection index);
    4£(C) ½«SQLÓi¾a¸øMySQLÖ´ÐУº$result = mysql_query($sql, $conn); //Ôoɾ¸Ä²e¶¼ÊÇÕa¾a
    5£(C) ¼iË÷Êý¾Ý£ºµ»Ø¼Ç¼Êý£º$number_of_rows = mysql_num_rows($result);
    ½«¼Ç¼
    ÅÈeÊý×e£º$newArray = mysql_fetch_array($result);
    Àý×Ó£º
    <?php
    // open the connection
    $conn = mysql_connect("localhost", "joeuser", "somepass");
    // pick the database to use
    mysql_select_db("testDB",$conn);
    // create the SQL statement
    $sql = "SELECT FROM testTable";
    // execute the SQL statement
    $result = mysql_query($sql, $conn) or die(mysql_error());
    //go through each row in the result set and display data
    while ($newArray = mysql_fetch_array($result)) {
    // give a name to the fields
    $id = $newArray['id'];
    $testField = $newArray['testField'];
    //echo the results onscreen
    echo "The ID is $id and the text is $testField
    ";
    }
    ?>
    11¡¢ ½ÓÊܱiµ¥ÔªËØ£º$_POST[±iµ¥ÔªËØÃu]£¬
    È種$_POST[user]
    ½ÓÊÜurlÖÐqueryStringÖÐÖµ£¨GET
    ½Ê½£(C)£º$_GET[queryString]
    12¡¢×ªÏoÆaËuÒ³Ãae£ºheader("Location: http://www.samspublishing.com");
    13¡¢×Öu´®²Ù×÷£º
    1£(C)explode(¡°-¡±,str)¨®JavaÖеÄsplite
    2£(C)str_replace£¨$str1,$str2,$str3£(C) =>$str1Òª²eÕÒµÄ×Ö
    u´®£¬$str2ÓÃÀ´Ìae»»µÄ×Öu´®£¬$str3´ÓÕa¸o×Öu´®¿ªÊ¼²eÕÒÌae»»
    3£(C)substr_replace£º
    14¡¢session£º
    1£(C)´o¿ªsession£ºsession_start(); //Ò²¿ÉÒÔÔÚphp.iniÉeÖÃsession_auto_start=1£¬²»±ØÔÙÿ¸oscript¶¼Ð´Õa¾a£¬µ«ÊÇĬÈÏΪ0£¬Ôo±ØÐeҪд¡£
    2£(C)¸øsession¸³Öµ£º$_SESSION[session_variable_name]=$variable;
    3)ÃÎÊsession£º$variable =$_SESSION[session_variable_name];
    4£(C)Ïu»Ùsession£ºsession_destroy();
    15¡¢ÏÔʾ
    ÖÀaµÄÍeÕuÀý×Ó£º
    <?php
    //connect to database
    $conn = mysql_connect("localhost", "joeuser", "somepass")
    or die(mysql_error());
    mysql_select_db("testDB",$conn) or die(mysql_error());
    $display_block = "

    My Categories

    Select a category to see its items.

    "; //show categories first $get_cats = "select id, cat_title, cat_desc from store_categories order by cat_title"; $get_cats_res = mysql_query($get_cats) or die(mysql_error()); if (mysql_num_rows($get_cats_res) < 1) { //Èç¹u*µ»Ø¼Ç¼ÐÐÊýСÓÚ1£¬Ôo˵Ã÷ûÓÐ*ÖÀa $display_block = "

    Sorry, no categories to browse.

    "; } else { while ($cats = mysql_fetch_array($get_cats_res)) { //½«¼Ç¼*ÅÈe±aÁ¿$catsÖÐ $cat_id = $cats[id]; $cat_title = strtoupper(stripslashes($cats[cat_title])); $cat_desc = stripslashes($cats[cat_desc]); $display_block .= "

    $cat_title//µa»÷´Ëurl£¬Ë¢Ð±¾Ò³£¬µÚ28ÐжÁÈ¡cat_id£¬ÏÔʾÏaÓ¦*ÖÀaµÄÌoÄ¿
    $cat_desc

    "; if ($_GET[cat_id] == $cat_id) { //Ñ¡ÔñÒ»¸o*ÖÀa£¬¿´ÏÂÃaeµÄÌoÄ¿ //get items $get_items = "select id, item_title, item_price from store_items where cat_id = $cat_id order by item_title"; $get_items_res = mysql_query($get_items) or die(mysql_error()); if (mysql_num_rows($get_items_res) < 1) { $display_block = "

    Sorry, no items in this category.

    "; } else { $display_block .= "
      "; while ($items = mysql_fetch_array($get_items_res)) { $item_id = $items[id]; $item_title = stripslashes($items[item_title]); $item_price = $items[item_price]; $display_block .= "
    • $item_title ($$item_price)"; [U2] } $display_block .= "
    "; } } } } ?> My Categories 16¡¢PHPÁ¬½ÓAccess£º open("driver=microsoft access driver (*.mdb);dbq=c:member.mdb"); $rs=$dbc->execute("select * from tablename"); $i=0; while (!$rs->eof){ $i+=1 $fld0=$rs->fields["UserName"]; $fld0=$rs->fields["Password"]; .... echo "$fld0->value $fld1->value ...."; $rs->movenext(); } $rs->close(); ?>
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例