大家有没有发现一个问题
当使用fread函数时,如果设置的文件指针指向一个ascii码小于33(十进制)的字符,则无论读取多长都读不出来,即得到一个长度为0的字符串。譬如下面情况:
当设置文件指针为18或者22时,
fseek($file,18,SEEK_SET);
$buffer=fread($file,4);
这个得到的$buffer长度为0
有没有不同看法啊
------解决方案--------------------
我试验过了,一切正常,没有发现你所说的状况,源码如下
$filename = "./1.gif";
$handle = fopen($filename, "rb+");
fseek($handle,12,SEEK_SET);
$buffer=fread($handle,4);
var_dump($buffer);
------解决方案--------------------
肯定是你哪里弄得不对了
//模拟一个文件<br /> $s = "424d6c0600000000000036000000280000001c00000014000000010018000000";<br /> $fp = tmpfile();<br /> fwrite($fp, pack('H*', $s));<br /> <br /> //以十六进制查看<br /> fseek($fp, 0);<br /> $i = 0;<br /> while($i < 32) {<br /> printf('%02x ', ord(fgetc($fp)));<br /> if((++$i % 16) == 0) echo PHP_EOL;<br /> }<br /> /*<br /> 42 4d 6c 06 00 00 00 00 00 00 36 00 00 00 28 00 <br /> 00 00 1c 00 00 00 14 00 00 00 01 00 18 00 00 00 <br /> */<br /> <br /> //进入你的问题<br /> fseek($fp, 18);<br /> $t = fread($fp, 4);<br /> echo strlen($t), ' : ', bin2hex($t);<br /> /*<br /> 4 : 1c000000<br /> */

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
