PHP Initial Knowledge

Source: Internet
Author: User
Tags script tag

1 What is PHPPHP (Hypetext Preprocessor) hypertext preprocessor, is a server-side, cross-platform, HTML embedded scripting language, its unique syntax mixed with the C language, Java language and Perl language features, only a widely used Kaiyuan multi-purpose scripting language, Especially suitable for web development.

2. Browser-to-server relationships

3. the data type in JS
    • Basic type
String number Boolean null defined
    • Reference type
Object (Array Math Date RegExp Object number String Boolean Funtion Error) 4. creation of one-dimensional arrays and two-dimensional arraysA two-dimensional array is an array that is nested in a one-dimensional array var arr = []; arr[0] = [n/a]; arr[1] = [4,5,6]; arr[2] = [7,8,9]; function Eacharr () { For (var i = 0; i < arr.length; i++) { For (var j = 0; J < Arr[i].length; J + +) { Console.log (arr[i][j]+ "<br/>");                 }             }         } Eacharr (arr); 5.PHP Code
    • Naming rules: Starting with $
    • All PHP code must be written to the inside of the tag
    • PHP is also a weakly typed language
    • Use echo when outputting.
$num = 123; Echo $num;//echo represents output (output to a static page)
    • <br/> for PHP to be swapped
echo ' <br/> '; Swap lines 6.PHP Arrays
    • Count---php built-in functions to calculate the length of the array
$arr = Array (123,456,789); For ($i = 0; $i < count ($arr); $i + +) { echo $arr [$i];          } foreach ($arr as $k = = $v) { echo $k;//index of the array echo ' <br/> ';//Swap echo $v;//values corresponding to the array index}
    • PHP array output printing in two ways---mainly for debugging
Print array Information Print_r ($arr); $arr = Array (+/-); Print_r ($arr);Array ([0] = 1 [1] = 2 [2] = 3) var_dump ($arr);-----more than Print_r () printed Var_dump ($arr);Printing results: Array (size=3)0= int11= int22= int3 7.PHP Common built-in functionsCount-----echo count ($arr 2);
    • Array_push (); Append an element to the end of the array
Array_pop (); Go to the last element after the coarse array echo; output Print_r (); Print array information var_dump ();//print array information, more details 8. Associative Arrays$arr = Array (1,2,3,4); $arr = Array (' attr1 ' = ' hello ', ' attr2 ' = ' Hi ', ' attr3 ' = ' Nihao '); two ways to define a 9.PHP array$arr = array, $arr [] = 1; $arr [] = 2; $arr [] = 3; 10.PHP Two-dimensional array
    • Two ways of defining
(1) $arr = Array ( Array (+/-), Array (1,2,3,4), Array (1,2,3,4,5)         );(2) $arr 1[] = Array (n/a); $arr 1[] = array (11,22,33); $arr 1[] = array (111,222,333); $arr 1[] = array (1111,2222,3333,44444);
    • Looping through two-dimensional arrays
(1) For loop traversal PHP two-dimensional array For ($i = 0; $i < count ($arr); $i + +) { For ($j = 0; $j < count ($arr [$i]); $j + +) { echo $arr [$i] [$j]. ' = = = = = ";         }     } echo ' <br> ';(2) Foreach Loop foreach ($arr as $value) { foreach ($value as $VV) { echo $vv. '-----';         }     } the string concatenation in 11.PHP is used. echo $str. '-----&nbsp;-----'. $num;Hello----------123 12.PHP the difference between single and double quotation marks
    • Double quotes parse variables in a string
    • Single quotes do not resolve variables in quotation marks
$num = 123; $str = ' Hello '; echo $str. '-----&nbsp;-----' $num;//hello----------123 echo ' <br/> '; echo ' Hello $num ';//hello $num echo "Hello $num";//hello 123 declaration of functions in 13.PHP <?php function F1 ($n) { $sum = 0; For ($i = 0; $i <= $n; $i + +) { $sum + = $i;     } return $sum;  } $result = F1 (+); echo ' <div> ' $result. ' </div> '; ?>14 If there is garbled at the beginning of the header (' Content-type:text/html;charset=utf-8 '); ----function: tells the browser to receive this page, as the page page display and use UTF-8 encoding displayheader (' content-type:text/html; Charset=utf-8 '); 15. The server gets the parameters that the client passed over(1) Get (2) post$_get[' parameter name ']$_post[' parameter name '] form form The default request method is get---query with GET request all the data is passed the parameter format after the URL parameter:? parameter name = argument value & parameter name = Parameter value GET request delivery of a limited number of stacks: 8,000 characters Form form submission can be method property specified (Get or post) from the form of the post-submitted data is submitted as a request body, there is no data in the URL post is generally used for a large number of data submissions request methods supported by the HTTP protocol (common)Get query data Post add data put update data delete delete data 16 Case: The server gets the parameters passed by the client. <form action= "06me.php" method= "get" > User name: <input type= "text" name= "username" ><br><br> Password: <input type= "password" name= "password" ><br> <input type= "Submit" value= "Submission" > </form> <?php $uname = $_get[' username '); $pwd = $_get[' password ');   //$uname = $_post[' username '); //$pwd = $_post[' password '); if ($uname = = ' Admin ' && $pwd = = ' 123 ') { echo ' login success '; } else { Echo ' User name or password error '; } ?> 18 Request mode and path(1) The way the front-end sends the request form the Action property of the A tag of the href attribute of the script tag of the SRC attribute of the link tag's href attribute to the SRC attribute of the img tag location.href = URL address (2) The current path and root path (absolute path) The current path./or omit the upper path: /absolute path (root path)) (http://my.com/) 19 two ways to dynamically generate static content in a page(1) <?php $arr = Array (' Orange ', ' apple ', ' banana '); ?> <div> Fruit List </div> <ul> <?php foreach ($arr as $key = = $value) { echo ' <li> ' $key. ' ----'. $value. ' </li> ';         }   ?> </ul>   (2) <div> Animal List </div> <?php $arr 2 = Array (' Dog ', ' pink ', ' mouse '); ?> <ul> <?php foreach ($arr 2 as $v) { ?> <li><?php echo $v?></li> <?php     } ?>

PHP Initial Knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.