PHP实用教程读书笔记,读书笔记:php_tizag_tutorial

3 ...4

PHP代码片段:

1 $quantity = $_GET['quantity'];2 $item = $_GET['item'];

3). 两者区别

GET传递数据是通过url,上面的例子中跳转到process.php页面是,会在url后面附上"?item=##&quantity=##",其中?是告诉浏览器接下来的这几项是变量.所以,传递重要信息如密码等,就不要使用GET方式传递数据,这样会完全暴露出来,非常不安全.

5.PHP创建文件

在PHP中,fopen函数用于打开一个文件,当该文件不存在时,就创建该文件.

1 $ourFileName = "testFile.txt";2 $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");3 fclose($ourFileHandle);

6.PHP打开文件

打开文件的方式有几种:

1). Read: 'r'

只读,文件指针在文件开头.

2). Write: 'w'

只写,文件指针在文件开头.而且会把之前的内容覆盖.

3). Append: 'a'

只写,文件指针在文件末尾.

7.PHP删除文件

使用unlink函数.

1 $myFile = "testFile.txt";2 unlink($myFile);

8.PHP在字符串里匹配字段

使用strpos函数返回相应字段位置.

举例如下:

1 $numberedString = "1234567890"; // 10 numbers from 1 to 02 $fivePos = strpos($numberedString, "5");3 echo "The position of 5 in our string was $fivePos";

结果如下:

1 The position of 5 in our string was 42 3 Finding All Occurrences in a String with Offset

举例如下:

1 $numberedString = "1234567890123456789012345678901234567890";2 $offset = 0; // initial offset is 03 $fiveCounter = 0;4 while($offset = strpos($numberedString, "5", $offset + 1)){5 $fiveCounter++;6 echo "

Five #$fiveCounter is at position - $offset";7 }

结果如下:

1 Five #1 is at position - 4 2 Five #2 is at position - 143 Five #3 is at position - 244 Five #4 is at position - 34

9.PHP分割字符串

使用explode函数.

举例如下:

1 $rawPhoneNumber = "800-555-5555";2 $phoneChunks = explode("-", $rawPhoneNumber);3 echo "Raw Phone Number = $rawPhoneNumber

";4 echo "First chunk = $phoneChunks[0]

";5 echo "Second chunk = $phoneChunks[1]

";6 echo "Third Chunk chunk = $phoneChunks[2]";

结果如下:

1 Raw Phone Number = 800-555-55552 First chunk = 8003 Second chunk = 5554 Third Chunk chunk = 5555

10.PHP连接字符串

使用implode函数.

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值