php--base

 

 

1 idea

  • A website is a folder
  • A web page is a file

2 concepts

  • url Uniform Resource Locator
  • URL: protocol: domain name [port number] [path] [filename]

3 variables

  • Start with $
  • It must be followed by a number or letter
  • After may also be digital
  • It can not be keywords
  • Try to see the name EENOW
  • Recommended small hump

4 Debug Helper

  1. True and false judgments: isset ()
  2. echo true / false: 1/0, the special value: null, echo corresponding variable (is null) is not output
  3. Output variables Complete information: var_dump ()
  4. Destruction variable: unset ()
  5. Splicing output: echo '<h1>', date ( 'Ymd H: i: s'), '</ h1>';

5 operating variables

  • Assignment
  • The value
  • It determines whether there is: isset ($ x);
  • Destruction: unset ($ x);

6 references

Similar to C ++ references, can be seen as an alias (data in memory is the same address)

$a = 1000;
$b = &$a;
$a = 100;

7 predefined variables

 

7.1 Get request parameters

  • $ _GET get request
  • $ _POST post request
  • $ _REQUEST (regardless of a get or post request)
<?php
$l = $r = $result = '';
if (isset($_REQUEST['l']) && $r = $_REQUEST['r']) {
    $l = $_REQUEST['l'];
    $r = $_REQUEST['r'];
    $result = $l + $r;
}
?>
<!--同时有 post get 数据-->
<form action="calc2.php?name=elem&age=12" method="post">
    <div>
    <input type="text"
           name="l"
           value="<?php echo $l; ?>"/>
    +
    <input type="text"
           name="r"
           value="<?php echo $l; ?>"/>
    <input type='submit' value="计算">
    <?php echo $result ?>
    </div>
</form>

7.2 $_SERVER

Only lists some simple, and the rest need to check the manual

echo '<p>php file: ', $_SERVER['PHP_SELF'];
echo '<p>domain name: ', $_SERVER['SERVER_NAME'];
echo '<p>server ip: ', $_SERVER['REMOTE_ADDR'];
echo '<p>document root path: ', $_SERVER['DOCUMENT_ROOT'];
echo '<p>script name: ', $_SERVER['SCRIPT_NAME'];
echo '<p>client ip: ', $_SERVER['REMOTE_ADDR'];

8 Variable Variable

Use variable name to find variables

$a = 1;
$b = 'a';
$c = 'b';
//$$$c;
//$$b;
//$a
echo $$$c;

9 Constant

 

9.1 const

Use only literals and simple calculation when defining expression

const AGE = 100;

echo 'len: ', LEN * 2 - 71;
echo '<br/>age: ', AGE * 2 - 33;

9.2 define

A time when the definition of the expression can be complex

define('LEN', 100);

echo 'len: ', LEN * 2 - 71;
echo '<br/>age: ', AGE * 2 - 33;

//避免冲突
$varName = 'AGE';
if(!defined($varName)){
    define($varName, 11);
}
echo '<br/>const value ', $varName, ' : ',constant($varName);

9.3 Predefined Constants

Some columns, other manual check

echo '<br/>', PHP_VERSION;
echo '<br/>', PHP_OS;
echo '<br/>', PHP_INT_MAX;
echo '<br/>', M_PI;

9.4 Magic constants

Some columns, other manual check

echo '<br/>', __DIR__;
echo '<br/>', __FILE__;
echo '<br/>', __LINE__;
//echo '<br/>', __FUNCTION__;

10 hex

Use the built-in function

// hexadecimal conversion 
$ A = 0x111; 
$ C = 111; 
$ B = 0111; 
$ D = 0b111; echo 'a 0x111:' $. A ;
 echo 'a 111:' $. B ;
 echo 'a 0111:' $. C ;
 echo '0b111 a:' . $ D ; // 10 decimal other transfer 
$ V = 100;
 echo 'a 100-> 16: ' , ' 0x ' , dechex ($ V );
echo'<br/>100->8: '

    

  , '0', decoct($v);
echo '<br/>100->2: ', '0b', decbin($v);

echo '<br/>011: ',octdec('011');

11 Float

Float equal unreliable operation, it should not be compared (usually turn integer comparison)

echo '<br/>1.6: ', 1.6;
echo '<br/>1.23e3: ', 1.23e3;

12 Boolean values

  • true
  • false

13 strings

  • Single quote does not resolve
  • Double quotes will resolve the variable ($ x)
  • After the double quotes does not resolve the variable escape, \ $ x will only take effect once, does not resolve the need to escape
$s = 'hello';
//效果相同
echo "<br/>$s";
echo "<br/>".$s;
echo '<br/>'.$s;

//效果相同
echo "<br/>\$s: $s";
echo '<br/>$s: '.$s;
echo '<br/>$s: ',$s;

Created: 2019-12-25 Wednesday 22:06

Validate

Guess you like

Origin www.cnblogs.com/heidekeyi/p/12099260.html