昨天在实验室花了一天时间看了英文版的php_tizag_tutorial,因为上学期用php和bootstrap写过一个租房网站,对php还是比较熟悉.现在总结一下php_tizag_tutorial里面一些没用过或者遗忘的知识点.
1.打印的字符串里面包含引号时,要注意采取下面的两种方式之一:
1). 在引号前加上反斜杠"\".
2). 使用单引号.
举例如下:
1 <?php2 // This won't work because of the quotes around specialH5!3 echo "<h5 id="I-love-using-PHP">I love using PHP!</h5>";4 // OK because we escaped the quotes!5 echo "<h5 id="I-love-using-PHP">I love using PHP!</h5>";6 // OK because we used an apostrophe '7 echo "<h5 id="I-love-using-PHP">I love using PHP!</h5>";8 ?>
2.String Creation Heredoc
使用注意标识符要在单独一行,不可缩进.
举例如下:
1 $my_string = <<<TEST2 Tizag.com3 Webmaster Tutorials4 Unlock your potential!5 TEST;6 echo $my_string;
输出结果:
1 Tizag.com Webmaster Tutorials Unlock your potential!
3.include函数与require函数的区别
使用include函数时,若出现错误,只是提出警告,代码依然执行下去;使用require函数时,则会报错,并且终止执行下去.
强烈推荐使用后者.
4.POST与GET的区别
1). POST
HTML代码片段:
1 <form action="process.php" method="post">2 <select name="item">3 ...4 <input name="quantity" type="text" />
PHP代码片段:
1 $quantity = $_POST['quantity'];2 $item = $_POST['item'];
2). GET
HTML代码片段:
1 <form action="process.php" method="get">2 <select name="item">3 ...4 <input name="quantity" type="text" />
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 "<br />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 <br />";4 echo "First chunk = $phoneChunks[0]<br />";5 echo "Second chunk = $phoneChunks[1]<br />";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函数.

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

SublimeText3汉化版
中文版,非常好用