[php learn] php 从头开始学习1
前言:大概在2006年的时候,学习过一段时间的php,并且当时做了一个下载的网站,后来由于读研究生阶段用的是java、j2ee相关,所以php就搁浅掉了,php这些年也发生了很大的变化,最大一个变化是支持面向对象了。
现在由于需要php做些东西,再次学习,从头开始!
echo 和 print 之间的差异:
- echo - 能够输出一个以上的字符串
- print - 只能输出一个字符串,并始终返回 1
设置 PHP 常量
如需设置常量,请使用 define() 函数 - 它使用三个参数:
- 首个参数定义常量的名称
- 第二个参数定义常量的值
- 可选的第三个参数规定常量名是否对大小写敏感。默认是 false。
<?phpdefine ("GREETING", "Welcome to W3School.com.cn!");echo GREETING;?>
运算符 | 名称 | 例子 | 结果 |
---|---|---|---|
== | 等于 | $x == $y | 如果 $x 等于 $y,则返回 true。 |
=== | 全等(完全相同) | $x === $y | 如果 $x 等于 $y,且它们类型相同,则返回 true。 |
!= | 不等于 | $x != $y | 如果 $x 不等于 $y,则返回 true。 |
不等于 | $x $y | 如果 $x 不等于 $y,则返回 true。 | |
!== | 不全等(完全不同) | $x !== $y | 如果 $x 不等于 $y,且它们类型不相同,则返回 true。 |
> | 大于 | $x > $y | 如果 $x 大于 $y,则返回 true。 |
大于 | $x | 如果 $x 小于 $y,则返回 true。 | |
>= | 大于或等于 | $x >= $y | 如果 $x 大于或者等于 $y,则返回 true. |
小于或等于 | $x | 如果 $x 小于或者等于 $y,则返回 true。 |
$car=array("Volvo","BWM","Jeep");
var_dump($car);
Syntax
code to be executed;
}
Example
foreach ($colors as $value) {
echo "$value
";
}
?>
PHP Global Variables - Superglobals
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 PHP superglobal variables are:
- $GLOBALS
- $_SERVER
- $_REQUEST
- $_POST
- $_GET
- $_FILES
- $_ENV
- $_COOKIE
- $_SESSION
Element/Code | Description |
---|---|
$_SERVER['PHP_SELF'] | Returns the filename of the currently executing script |
$_SERVER['GATEWAY_INTERFACE'] | Returns the version of the Common Gateway Interface (CGI) the server is using |
$_SERVER['SERVER_ADDR'] | Returns the IP address of the host server |
$_SERVER['SERVER_NAME'] | Returns the name of the host server (such as www.w3schools.com) |
$_SERVER['SERVER_SOFTWARE'] | Returns the server identification string (such as Apache/2.2.24) |
$_SERVER['SERVER_PROTOCOL'] | Returns the name and revision of the information protocol (such as HTTP/1.1) |
$_SERVER['REQUEST_METHOD'] | Returns the request method used to access the page (such as POST) |
$_SERVER['REQUEST_TIME'] | Returns the timestamp of the start of the request (such as 1377687496) |
$_SERVER['QUERY_STRING'] | Returns the query string if the page is accessed via a query string |
$_SERVER['HTTP_ACCEPT'] | Returns the Accept header from the current request |
$_SERVER['HTTP_ACCEPT_CHARSET'] | Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1) |
$_SERVER['HTTP_HOST'] | Returns the Host header from the current request |
$_SERVER['HTTP_REFERER'] | Returns the complete URL of the current page (not reliable because not all user-agents support it) |
$_SERVER['HTTPS'] | Is the script queried through a secure HTTP protocol |
$_SERVER['REMOTE_ADDR'] | Returns the IP address from where the user is viewing the current page |
$_SERVER['REMOTE_HOST'] | Returns the Host name from where the user is viewing the current page |
$_SERVER['REMOTE_PORT'] | Returns the port being used on the user's machine to communicate with the web server |
$_SERVER['SCRIPT_FILENAME'] | Returns the absolute pathname of the currently executing script |
$_SERVER['SERVER_ADMIN'] | Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as [email protected]) |
$_SERVER['SERVER_PORT'] | Returns the port on the server machine being used by the web server for communication (such as 80) |
$_SERVER['SERVER_SIGNATURE'] | Returns the server version and virtual host name which are added to server-generated pages |
$_SERVER['PATH_TRANSLATED'] | Returns the file system based path to the current script |
$_SERVER['SCRIPT_NAME'] | Returns the path of the current script |
$_SERVER['SCRIPT_URI'] | Returns the URI of the current page |
PHP $_REQUEST
Example
$name = $_REQUEST['fname'];
echo $name;
?>
PHP $_POST
PHP $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.
Example
$name = $_POST['fname'];
echo $name;
?>
上述正则表达式规定字符m可以在匹配对象中连续出现2-6次,
\S:用于匹配除单个空格符之外的所有字符;
\d:用于匹配从0到9的数字;
\w:用于匹配字母,数字或下划线字符;
\W:用于匹配所有与\w不匹配的字符;
. :用于匹配除换行符之外的所有字符。
因为上述正则表达式模式以“\b”定位符开头,所以可以与目标对象中以 “bomb”, 或 “bom”开头的字符串相匹配。
/man\b/
因为上述正则表达式模式以“\b”定位符结尾,所以可以与目标对象中以 “human”, “woman”或 “man”结尾的字符串相匹配。

의존성 (di) inphpenhancescodeflexibility 및 testability는 decouplingdependencycreation fromusage.toimplementDieffectically : 1) addicontainersjudicuelyToavoidover-Engineering.2) indhe. 3) adhe

toimproveyourphpwebsite의 성능, UsetheseStrospations : 1) ubstractOpCodeCachingWithOpCaceToSpeedUpscriptScriptIngretation.2) 최적화 된 AabaseQueriesBysElectingOnlynecessaryFields.3) UsecachingsystemsLikeredSormcedUcedUcedUcedALOW

예, itispossibletosendmassemailswithphp.1) uselibraries -lifephpmailerorswiftmailerforfficialemailsending.2) emubledelaysbetemailstoavoidspamflags.3) personalizeemailsingdynamiccontenttoimproveengement.4) usequeuesystemslikerbitmbitmquredisb

의존성 (di) inphpisadesignpatternthatachievesinversionofcontrol (ioc) by ancelociestobeinjectedintoclasses, 향상 모듈 성, 테스트 가능성 및 flexibility.didecouplesssclassessfromspecificimplementations, codemoremanageableandadapt

PHP를 사용하여 이메일을 보내는 가장 좋은 방법은 다음과 같습니다. 1. 기본 전송에 Php 's Mail () 함수를 사용합니다. 2. phpmailer 라이브러리를 사용하여 더 복잡한 HTML 메일을 보내십시오. 3. Sendgrid와 같은 트랜잭션 메일 서비스를 사용하여 신뢰성 및 분석 기능을 향상시킵니다. 이러한 방법을 사용하면 이메일이받은 편지함에 도달 할뿐만 아니라 수신자를 유치 할 수 있습니다.

PHP 다차원 어레이에서 총 요소 수를 계산하는 것은 재귀 적 또는 반복적 인 방법을 사용하여 수행 할 수 있습니다. 1. 재귀 방법은 배열을 가로 지르고 중첩 배열을 재귀 적으로 처리함으로써 계산됩니다. 2. 반복 방법은 스택을 사용하여 깊이 문제를 피하기 위해 재귀를 시뮬레이션합니다. 3. Array_Walk_Recursive 함수도 구현할 수 있지만 수동 계산이 필요합니다.

PHP에서, do-while 루프의 특성은 루프 본체가 적어도 한 번 실행되도록하고 조건에 따라 루프를 계속할지 여부를 결정하는 것입니다. 1) 조건부 점검 전에 루프 본체를 실행하며, 사용자 입력 확인 및 메뉴 시스템과 같이 작업을 적어도 한 번 수행 해야하는 시나리오에 적합합니다. 2) 그러나, do-while 루프의 구문은 초보자들 사이에서 혼란을 야기 할 수 있으며 불필요한 성능 오버 헤드를 추가 할 수 있습니다.

PHP의 효율적인 해싱 스트링은 다음 방법을 사용할 수 있습니다. 1. 빠른 해싱에 MD5 기능을 사용하지만 비밀번호 저장에는 적합하지 않습니다. 2. SHA256 기능을 사용하여 보안을 향상시킵니다. 3. Password_hash 함수를 사용하여 비밀번호를 처리하여 최고 보안과 편의성을 제공하십시오.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구

드림위버 CS6
시각적 웹 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.