博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP: Learning Notes
阅读量:5964 次
发布时间:2019-06-19

本文共 3672 字,大约阅读时间需要 12 分钟。

from .

php basics

in PHP, variables are defined as $_alphanum 

variables should always prefixed a $

variables defined/assigned outside of a function cannot be used inside a function, unless declared inside function with keyword global $var. Also can be used as $GLOBALS['var'] for in/out.

echo variables: (all of the 3 examples are okay)

echo $xecho "x is equal to $x"echo "x is equal to " . $x

comments can be:

# comments// comments/* comments */

the static keyword inside function keeps the variable change everytime calls the function.

to include scripts from other php file:

require is basically the same as include, except for its not stop running following scripts when not finding the mentioned php file.

----

php functions

echo: what echo echoes is pure-html, can be tagged htmls. echo strings concat using .,  echo variables can do math ops. echo multiple elements separated by ,

print: print only accept one element, returns 1, slower

---

php types

  • String
  • Integer
  • Float (floating point numbers - also called double)
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

var_dump($var) function dumps a var together with its type

bool: false true

create arrays by array() constructor. $x= array("a","b","c")

object are instances of class, class can be defined by:

class Car {    function Car() {        $this->model = "VW";    }}

instantialize it to object by new:

$herbie = new Car();

any var created without init is as null.

resource type: relating to db calls

---

php string manipulating

strlen(): counts to last '\0'

str_word_count(): counts words

strrev(), reverse a string str->rts

strpos(str, pattern), returns start of pattern idx in str

str_replace(patt, rep, str) returns str's all pattern replaced by rep

complete list of string funcs:

----

php constants

define(name,value[,opt-case-sensitive])

----

php arith

===, ==, !=, !==, ++, --, and(&&), or(||), xor, !,

.=: str concat

---

php cond

if, switch($var)->case:->break->default:

---

php function

---

php array

count($arr) returns count of array elems

array can also be created in associative way:

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");foreach($age as $x => $x_value) {    echo "Key=" . $x . ", Value=" . $x_value;    echo "
";}

array can be called recursively to create multi-level array

complete array intro is .

sorting an array in different ways: sort, rsort, asort, ksort, arsort, krsort.. indexed/associative arrays are sorted using different functions

---

php globals

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION

$GLOBALS is introd before

$_SERVER['HTTP_USER_AGENT'] returns user-agent field of the incoming request. other fields can be PHP_SELF, SERVER_NAME, HTTP_HOST, SCRIPT_NAME, REQUEST_METHOD.. more to look at .

$_REQUEST['varname'] is used to collect the value of the input field from a form.

$_POST['varname'] is used to collect the value of a post http request with key=varname

$_GET['varname'] is used to collect the value of a request which has uri: domain.com/page.html?varname=value 

post key-values may be embedded in ssl/tls, so its sneaker than get option

----

php file operations

$file = fopen("filename","r");while(!feof($myfile)) {  echo fgets($myfile) . "
";}fclose($file);

fgets get one line at a time, fgetc get one char at a time.

after configuring php.ini: file_uploads = On

we can upload file as .

----

php cookie

setcookie(name, value, expire, path, domain, secure, httponly);isset($_COOKIE[$cookie_name])

----

php session

";echo "Favorite animal is " . $_SESSION["favanimal"] . ".";// remove all session variablessession_unset(); // destroy the session session_destroy(); ?>

 

转载于:https://www.cnblogs.com/sansna/p/7891754.html

你可能感兴趣的文章
NSDate 时间
查看>>
敏捷开发方法综述
查看>>
天。鬼。法
查看>>
linux tcp中time_wait
查看>>
shuff打乱排序
查看>>
LC.155. Min Stack(非优化,两个stack 同步 + -)
查看>>
Add Two Numbers
查看>>
Asp.net技巧:gridview获取当前行索引的方法
查看>>
让 vim 在按ESC时自动保存
查看>>
git配置别名
查看>>
SpringMVC配置文件
查看>>
划分数系列问题
查看>>
springboot整合jersey
查看>>
Hibernate实体对象的生命周期(三种状态)
查看>>
23. Merge k Sorted Lists
查看>>
Python:pygame游戏编程之旅七(pygame基础知识讲解1)
查看>>
java B转换KB MB GB TB PB EB ZB
查看>>
通过SharpZipLib实现文件夹压缩以及解压
查看>>
20145209预备作业02
查看>>
精通CSS滤镜(filter)
查看>>