请教下PHP生成静态页如何返回路径
我自己做了个网站,现在需要加入静态化功能
模板文件
{$v['typedir']} 这个是返回当前数据库栏目路径的
现在问题是静态化时路径不是全部静态化,有些比如评论,和某些需要经常更新的地方要用动态路径
我现在后台静态化解析模板时和动态解析模板都是用的同一个解析函数
$str = preg_replace('/\{mzrui:([\w]+)\s+([^}]+)\}/ie',"self::mzrui_tag('$1','$2')",$str); //匹配模板文件数据库查询语句
public static function mzrui_tag($tab,$sql) //mysql 解析
{
global $mz_mysql,$prefix;
preg_match_all("/([a-z]+)\=[\']?([^\']+)[\']?/i", stripslashes($sql), $matches, PREG_SET_ORDER);
$check = array('type','rows','table','order','limit');
foreach($matches as $v)
{
if(in_array($v[1],$check))
{
$$v[1] = $v[2]; //变量的变量
}
}
switch($tab)
{
case 'channel': // 导航栏标签
{
$result = $mz_mysql->sql("select * from ".$prefix."kind where kind=0");
while($v = mysql_fetch_array($result))
{
if($v['html'] == 0) // 这里判断如果没有生成静态栏目时就返回动态链接 否则就取数据库内的静态文件夹地址
{
$v['typedir'] = 'index.php?ac=list&id='.$v['uid'];
$str[] = $v;
}
}
$GLOBALS['data']=$str;
}
break;
case 'list': //文章栏目标签
{
if(!empty($_GET['id'])) // 这里判断如果是动态链接的话取当前分类栏目的ID,但是这里如果是后台生成静态化页面的话,这里就有问题
{
$id = $mz_mysql->sql("select * from ".$prefix."kind where uid=".$_GET['id']);
}
}
break;
}
return ''; //返回数据
}
现在要解决就是路径的返回问题和栏目ID的问题,现在思路很混乱,忘有经验的指点一下
------解决方案--------------------
你是用的cms吗?如果全是自己写的不可能不会啊
静态化很简单,就是把输出的这个变量放到一个指定格式(html)的文件即可啊,
函数file_put_contents() 或者fwrite(),都可以,在放入的时候本身就需要指定路劲的

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools
