有以下模板代码,上下两个div的模板,我喜欢上面那个div的写法,因为缩进和对齐都好了,用下面的写法会导致难以阅读维护
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /><title>aafdsa</title><style type="text/css">a{margin:0; padding:0}</style></head><body><div id="div1"><?php foreach($ar1 as $bbb): ?> <a href="http://www.baidu.com?xxx=<?php echo $bbb ;?>"><?php echo $bbb ;?></a><?php endforeach; ?></div><div id="div2"><?php foreach($ar1 as $bbb): ?><a href="http://www.baidu.com?xxx=<?php echo $bbb ;?>"><?php echo $bbb ;?></a><?php endforeach; ?></div></body></html>
视图对象控制的代码是这样的
$ar1 = array(1,2,3,4,5,6,7); //extract($this->data);ob_start('ob_gzhandler');ob_implicit_flush(0);include 'tpl.php';ob_flush();
然而输出的HTML呈以下效果(以下只贴上BODY部分算了)
<body><div id="div1"> <a href="http://www.baidu.com?xxx=1">1</a> <a href="http://www.baidu.com?xxx=2">2</a> <a href="http://www.baidu.com?xxx=3">3</a> <a href="http://www.baidu.com?xxx=4">4</a> <a href="http://www.baidu.com?xxx=5">5</a> <a href="http://www.baidu.com?xxx=6">6</a> <a href="http://www.baidu.com?xxx=7">7</a></div><div id="div2"><a href="http://www.baidu.com?xxx=1">1</a><a href="http://www.baidu.com?xxx=2">2</a><a href="http://www.baidu.com?xxx=3">3</a><a href="http://www.baidu.com?xxx=4">4</a><a href="http://www.baidu.com?xxx=5">5</a><a href="http://www.baidu.com?xxx=6">6</a><a href="http://www.baidu.com?xxx=7">7</a></div></body>
我企图用排版规范的写法,但又企图输出下面那个div2的a标签不换行的效果,不知道这样可不可以实现.我以为
ob_start('ob_gzhandler');
这个设置可以使得被压缩,但却没有.
我在奇怪thinkphp框架是怎么弄的,我在它那里面是规范排版模板代码的,但它输出的却是压缩的.可能是因为它编译的原因.我没有统计,直接include...
那么请问大家有没有什么办法指导一下?非得编译?
回复讨论(解决方案)
ob_start('compact_format');function compact_format($buffer) { return preg_replace("/[\r\n]+\s*/", '', $buffer);}echo <<< TXT<div id="div1"> <a href="http://www.baidu.com?xxx=1">1</a> <a href="http://www.baidu.com?xxx=2">2</a> <a href="http://www.baidu.com?xxx=3">3</a> <a href="http://www.baidu.com?xxx=4">4</a> <a href="http://www.baidu.com?xxx=5">5</a> <a href="http://www.baidu.com?xxx=6">6</a> <a href="http://www.baidu.com?xxx=7">7</a></div>TXT;//执行以下,看看效果
ob_start('compact_format');function compact_format($buffer) { return preg_replace("/[\r\n]+\s*/", '', $buffer);}echo <<< TXT<div id="div1"> <a href="http://www.baidu.com?xxx=1">1</a> <a href="http://www.baidu.com?xxx=2">2</a> <a href="http://www.baidu.com?xxx=3">3</a> <a href="http://www.baidu.com?xxx=4">4</a> <a href="http://www.baidu.com?xxx=5">5</a> <a href="http://www.baidu.com?xxx=6">6</a> <a href="http://www.baidu.com?xxx=7">7</a></div>TXT;//执行以下,看看效果
嗯谢谢,这样是可以.就是要执行一下正则处理了.
我以为利用PHP自带的输出机制可以完成.

依賴性注射inphpisadesignpatternthatenhancesFlexibility,可檢驗性和ManiaginabilybyByByByByByExternalDependencEctenceScoupling.itallowsforloosecoupling,EasiererTestingThroughMocking,andModularDesign,andModularDesign,butquirscarecarefulscarefullsstructoringDovairing voavoidOverOver-Inje

PHP性能優化可以通過以下步驟實現:1)在腳本頂部使用require_once或include_once減少文件加載次數;2)使用預處理語句和批處理減少數據庫查詢次數;3)配置OPcache進行opcode緩存;4)啟用並配置PHP-FPM優化進程管理;5)使用CDN分發靜態資源;6)使用Xdebug或Blackfire進行代碼性能分析;7)選擇高效的數據結構如數組;8)編寫模塊化代碼以優化執行。

opcodecachingsimplovesphperforvesphpermance bycachingCompiledCode,reducingServerLoadAndResponSetimes.1)itstorescompiledphpcodeinmemory,bypassingparsingparsingparsingandcompiling.2)useopcachebachebachebachebachebachebachebysettingparametersinphametersinphp.ini,likeememeryconmorysmorysmeryplement.33)

依賴注入在PHP中通過外部注入方式提供對象依賴,提高代碼的可維護性和靈活性。其實現方式包括:1.構造函數注入,2.設值注入,3.接口注入,使用依賴注入可以解耦、提高可測試性和靈活性,但需注意可能增加複雜性和性能開銷。

在PHP中實現依賴注入(DI)可以通過手動注入或使用DI容器來完成。 1)手動注入通過構造函數傳遞依賴,如UserService類註入Logger。 2)使用DI容器可以自動管理依賴,如Container類管理Logger和UserService。實現DI可以提高代碼的靈活性和可測試性,但需要注意過度注入和服務定位器反模式等陷阱。

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

stickysessensureuserRequestSarerOutedTothesMeServerForsessionDataConsisterency.1)sessionIdentificeAssificationAssigeaSsignAssignSignSuserServerServerSustersusiseCookiesorUrlModifications.2)一致的ententRoutingDirectSsssssubsequeSssubsequeSubsequestrequestSameSameserver.3)loadBellankingDisteributesNebutesneNewuserEreNevuseRe.3)

phpoffersvarioussessionsionsavehandlers:1)文件:默認,簡單的ButMayBottLeneckonHigh-trafficsites.2)Memcached:高性能,Idealforsforspeed-Criticalapplications.3)REDIS:redis:similartomemememememcached,withddeddeddedpassistence.4)withddeddedpassistence.4)databases:gelifforcontrati forforcontrati,有用


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

WebStorm Mac版
好用的JavaScript開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Atom編輯器mac版下載
最受歡迎的的開源編輯器