simple grammer
<?php
echo strlen("Hello world!"); // outputs 12
?>
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
<?php
echo strrev("Hello world!"); // outputs !dlrow olleH
?>
<?php
echo strpos("Hello world!", "world"); // outputs 6. If no match is found, it will return FALSE.
?>
<?php
echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
?>
<?php
define("GREETING", "Welcome to W3Schools.com!"); // syntax: define(name, value, case-insensitive)
echo GREETING;
?>
operation
=== $x === $y return true if $x is equal to $y, and they are of the same type
<> $x <> $y return true if $x is not equal to $y
!== $x !== $y return true if $x is not equal to $y, or they are not of the same
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}
e.g:
<?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
foreach ($array as $value) {
code to be executed;
}
e.g:
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
<?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars); //output 3
?>
PHP Associative Arrays:associative arrays are arrays that use named keys that you assigin to them
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Sort Funcitions For Arrays
sort() -- sort arrays in ascending order
rsort() -- sort arrays in descending order
asort() -- sort associative arrays in ascending order, according to the value
ksort() -- sort associative arrays in ascending order, according to the key
arsort() -- sort associative arrays in descending order, according to the value
krsort() -- sort associative arrays in descending order, according to the key
Superglobals: PHP Global Variables
Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.
The PHO superglobal variables are:
$GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION
<?php
echo $_SERVER['PHP_SELF']; // Returns the filename of the currency executing script
echo "<br>";
echo $_SERVER['SERVER_NAME']; // Returns the IP address of the host server
echo "<br>";
echo $_SERVER['HTTP_HOST']; // Returns the host header from the current request
echo "<br>";
echo $_SERVER['HTTP_REFERER']; // Returns the complete URL of the current page
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME']; // Return the URI of the current page
?>
$_SERVER['GATEWAY_INTERFACE'] returns the version of the Common Gateway Interface the server is using
$_SERVER['SERVER_ADDR'] returns the IP address of the host server
$_SERVER['SERVER_SOFTWARE'] returns the server identification string
$_SERVER['SERVER_PROTOCOL'] returns the name and reversion of the information protocol
$_SERVER['REQUEST_METHOD'] return the request method used to access the page
$_SERVER['QUERY_STRING'] return the query string if the page is accessed via a query string
$_SERVER['HTTP_ACCEPT'] return the Accept header from the current request
$_SERVER['HTTPP_ACCEPT_CHARSET'] return the Accept_Charset header from the current request
$_SERVER['HTTP_HOST'] return the host header from the current request
$_SERVER['HTTP_REFERER'] return the complete URL of the current page
$_SERVER['HTTPS'] is the script queried through a secure HTTP protocol
$_SERVER['REMOTE_ADDR'] return the IP address from where the user is viewing the current page
$_SERVER['REMOTE_HOST'] return the host name from where the user is viewing the current page
$_SERVER['REMOTE_PORT'] return the port being used on the user's machine to communicate with the web server
$_SERVER['SCRIPT_FILENAME'] return the absolute pathname of the currently executing script
$_SERVER['SERVER_ADMIN'] return the value given to the SERVER_ADMIN directive in the web server configuration file
$_SERVER['SERVER_PORT'] return the port on the server machine being used by the web server for communication
$_SERVER['SERVER_SIGNATURE'] return the server version and virtual host name which are used by the web server for communication
$_SERVER['PATH_TRANSLATED'] return the file system based path to the current script
$_SERVER['SCRIPT_NAME'] return the path of current script
$_SERVER['SCRIPT_URI'] return the URI of the current page
PHP $_REQUEST is used to collect data after submitting an HTML form
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_REQUEST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
PHP $_POST is used to collect form data after submitting an HTML form with method = "post",$_POST is also widely used to pass variables
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
PHP $_GET is used to collect form data after submitting an HTML form with method="get".$_GET can also collect data sent in the URI
<html>
<body>
<?php
echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
?>
</body>
</html>
simple grammer的更多相关文章
- PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)
最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...
- Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】
原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- 设计模式之简单工厂模式Simple Factory(四创建型)
工厂模式简介. 工厂模式专门负责将大量有共同接口的类实例化 工厂模式可以动态决定将哪一个类实例化,不必事先知道每次要实例化哪一个类. 工厂模式有三种形态: 1.简单工厂模式Simple Factory ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 关于The C compiler "arm-none-eabi-gcc" is not able to compile a simple test program. 的错误自省...
在 GCC ARM Embedded https://launchpad.net/gcc-arm-embedded/ 上面下载了个arm-none-eabi-gcc 用cmake 编译时 #指定C交叉 ...
随机推荐
- OC 实例方法和类方法区别
Objective-C里面既有实例方法也类方法.类方法(Class Method) 有时被称为工厂方法(Factory Method)或者方便方法(Convenience method).工 ...
- oAuth协议学习
我们的项目需要为一个认证网站开发一套API,这些API可以提供给很多公司来调用,但是公司在调用之前,必须先做授权认证,由此接触到了oAuth协议. 以下内容来自网络整理 定义 OAUTH协议为用户资源 ...
- HTML第二部分表单及使用Photoshop快速制作网页
一.表单 <form id="" name="" method="post/get" action="负责处理的服务端&qu ...
- 通过计算机名访问linux
1.安装samba 2.设置/etc/samba/smb.conf的 netbois name 配置节的值为你要设置的名称,如 netbois name = mylinux 也可以不设置此项,如果不设 ...
- 微信浏览器——User Agent
在iPhone 返回 Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gec ...
- web开发-前端到服务器Controller中的数据传递
一, ajax方式 1. ajax获取页面中的数据,包括表单中的数据, 然后封装成对象,数组, 字符串, 或其他基本类型的数据. 2. 将封装得到的数据通过ajax传递到controller中(注:在 ...
- 转: Oracle中的物化视图
物化视图创建语法:CREATE MATERIALIZED VIEW <schema.name>PCTFREE <integer>--存储参数PCTUSED <intege ...
- php file_get_contents curl发送cookie,使用代理
$auth = base64_encode('LOGIN:PASSWORD');//LOGIN:PASSWORD 这里是你的账户名及密码 $aContext = array( 'http' => ...
- CENTOS 修改MYSQL文件到内存盘
# 必须说明的是: # 0 内存盘的特性是断电就丢数据. # 1 对数据时效性要求高的自己做主从 # 2 重启or关机必须导出数据和开机加载数据. # 3 最好弄个脚本 开关机自己调用. # 4 简单 ...
- iScroll 优化
iScroll 它比较好的解决了移动互联网 web app 滚动支持问题以及点击事件缓慢的问题,经过简单配置即可让 web app 像原生 app 一样流畅,甚至都不需要改变原来的编码方式,目前它几乎 ...