跟着开发手册学习php

来源:互联网 发布:linux nanosleep使用 编辑:程序博客网 时间:2024/05/16 14:52

1.例子程序

<html><head><title>demon</title></head><body><?phpecho "hello";?></body></html>

2、查看所用浏览器

<html><head><title>firstdemon</title></head><body><?phpecho $_SERVER["HTTP_USER_AGENT"];?></body></html>

3、strpos查找字符

<?phpif(strpos($_SERVER["HTTP_USER_AGENT"],"hrom")!==false){?><h3>strpos must have returned non-false</h3><center><b>you are using internet</b></center><?php}else{?><h3>strpos must have returned false</h3><center><b>you are not using internet</b></center><?php}?>

4、form表单

<form action="action.php" method="POST"> Your name: <input type="text" name="name" /> Your age: <input type="text" name="age" /> <input type="submit"></form>

  自动全局变量

Welcome <?php echo $_POST["name"]; ?>.<br/>you are <?php echo $_POST["age"]; ?>years old.


5、  自动全局数组变量: $_GET$_POST$_COOKIE$_SERVER$_FILE$_ENV$_REQUEST 以及$_SESSION


6、从HTML中分离

<?phpif (1) {    ?>    <strong>This is true.</strong>    <?php} else {    ?>    <strong>This is false.</strong>    <?php}?> 


7、“单行”注释仅仅注释到行末或者当前的 PHP 代码块,视乎哪个首先出现。 

<h1>This is an <?php # echo "simple";?> example.</h1>


8、字符串可以用三种字面上的方法定义。

  • 单引号             和其他两种语法不同,单引号字符串中出现的变量和转义序列不会被变量的值替代。

  • 双引号             双引号字符串最重要的一点是其中的变量名会被变量值替代

  • 定界符





原创粉丝点击