PHP (i)

Source: Internet
Author: User

PHP (Hypertext preprocessor Hypertext Preprocessor)

1. Tools such as environmental tools XAMPP

  

2.apache Configuration

The default Apache path is the C:/xampp/apache folder

You can modify the root configuration to your project's folder for ease of use

The path is as follows (requires restarting Apache to take effect after modification)

the paths that need to be modified are as follows (the two paths are unified)

  

expand modify localhost local masquerading domain name

3. Syntax

PHP file defaults to. php End

Start with <?php end With ?> (omit?> if no other language ends)

The end of each line must have; End otherwise error

  Echo

    echo outputs strings to the page for debugging purposes (only output strings, output other error)

  Stitching strings

Use. Stitching strings

 Variable

Case-sensitive with ' $ + variable name ' beginning with letter or underscore

  Constant 

A low version with the Define () function defines a type that can be defined with a Boolean integer float and a String

Define (' HAHA ', ' aha haha ');    // the defined constant name is the uppercase string echo HAHA;        // The output of the constant name is also capitalized

A high version can be defined with a const definition with the ES6

Notes

Same as JS //Single line comment/**/paragraph comment

  Delimiter

$str = <<<EOD //eod is random, as long as it's consistent with the back, it's written here. Output  can be output when output
Keep indent EOD; End and start must stick to the left of the write

echo "<pre>"; Keep formatting
echo $str;//Pay attention to recommended writing? > End If you do not write the end, do not have a blank space will be error

  Array

<? PHP
$hero Array (' mage ' = ' ann ', ' tank ' = ' Cheng '); // defines an array of low version 5. Few, no 6. Several versions of the $hero = [' Mage ' and ' Ann ', ' tank ' = ' golden ') ' the method for defining an array after the//5.4 version is now 7. Echo ' <pre> '; // formatted output for easy observation Print_r ($hero// print array Var_dump ($hero// print belt type ?>

    Multidimensional arrays

  

$hero = [  '    mage ' = [' Ann's ', ' N '    ,    ' Wang Zhaojun ',    ],  ' tank ' = > [    ' cheng Bite Gold ',    ' Xiang Yu ',    ' Zhang Fei ',  ],]; $fashi $hero [' Mage ']; Print_R ($fashi);

Iterating through an array

one-dimensional arrays

 <? php   $hero  = [' ann ', ' Chen Bites ', ' Xiang Yu ']; //   defines an array  for  ( $i  = 0;  $i  < count  (  $hero );  $i  ++ echo  "<li>".  $hero  [ $i ]. " </li> "; //  }; ? 
<? PHP $hero = [' mage ' = ' ann ', ' tank ' = ' chen Bite Gold ']; // Defining Arrays  foreach ($heroas$key$value)    {//foreach loop this with more Echo $key $value . ' <br> ';  }? >

    Multidimensional arrays

  $hero= [    ' Mage ' =[      ' Anne-La ', ' Wang Zhaojun ', '      ], ' tank ' = [      ' Cheng Jin ', ' Xiang Yu ', ' Zhang Fei ',    ],  ]; foreach($hero  as $leixing=$list) {    Echo' <br> '.$leixing. ' <br> '; //For ($i = 0; $i < count ($list); $i + +) {//Echo $list [$i]; // }    foreach($list  as $name) {      Echo' Name '.$name; }  }?>

  PHP page and HTML page mixed line color gehuanghuanse.php

<! DOCTYPE html>pink{Background:Pink; } tableTrtd{Border:1px solid red; }  </style>PHP for($i= 0;$i< 20;$i++) {    ?> <tr <?phpif($i% 2 = = = 0) {Echo"Class= ' Pink '";}? >> <td>00</td> <td>01</td> <td>02</td> &LT;TD&GT;04&LT;/TD&G    T </tr> <?php}; ?> </table></body>

  Custom functions

<? PHP   function Fun ($name) {    echo ' run '. $name;  } Fun (' Wei bin '); // ===>run?>

  Simple Object-oriented

<? PHP   class Foo  {    publicfunction  fun1 () {      echo ' fun1 ';    }     Static function fun2 () {      echo ' fun2 ';    }  }   var New Foo;  Ofoo, fun1 ();  Ofoo, fun2 ();? >

 A simple API

<?PHP//User Information  classUser { Public Static functioninfo () {$info= [        ' id ' = 1, ' name ' = ' weibin ', ' age ' = ' ', ' password ' = ' 123456 ', ' sex ' = ' 1 ',      ]; returnJson_encode ($info); Json_encode () encoding Json_decode () decoding}}$userinfo= User::info (); A static class can be used without a new direct:: To accessPrint_r($userinfo);?>

PHP (i)

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.