<p id="bpegv"><strike id="bpegv"></strike></p>
  • <blockquote id="bpegv"><kbd id="bpegv"></kbd></blockquote><address id="bpegv"></address><p id="bpegv"><pre id="bpegv"></pre></p>\n border=\"1\" style=\"width: 80%;\">\n \n \n \n {% for product in products %}\n \n
    Product<\/td>\n Description<\/td>\n Value<\/td>\n Date<\/td>\n <\/tr>\n <\/thead>\n
    {{ product.name }}<\/td>\n {{ product.description }}<\/td>\n {{ product.value }}<\/td>\n {{ product.date_register|date(\"m\/d\/Y\") }}<\/td>\n <\/tr>\n {% endfor %}\n <\/tbody>\n <\/table>\n <\/body>\n<\/html><\/pre>\n

    此時,我們?nèi)匀粨碛邢嗤捻撁?,但我們通過分離上下文塊來降低了它的復(fù)雜性。<\/p>\n

    緩存<\/strong><\/p>

    Environment<\/code>對象不僅可以用于加載模板。如果我們使用關(guān)聯(lián)目錄的cache<\/code>選項傳遞,Twig將緩存編譯后的模板,從而避免在后續(xù)請求中解析模板。編譯后的模板將存儲在我們提供的目錄中。請注意,這是編譯模板的緩存,而不是已評估的模板的緩存。這意味著Twig將解析、編譯并保存模板文件。所有后續(xù)請求仍然需要評估模板,但第一步已經(jīng)為您完成。讓我們通過編輯bootstrap.php<\/code>文件來緩存示例中的模板:<\/p>\n

     Hello \" . $name . \"<\/p>\"; ?><\/pre>\n

    (以下內(nèi)容與原文類似,但做了部分語句調(diào)整和段落劃分,并保持了圖片位置不變)<\/strong><\/p>\n

    循環(huán)<\/strong><\/p>\n

    在我們的示例中,我們已經(jīng)看到了如何使用Twig進(jìn)行循環(huán)?;旧?,我們使用for<\/code>標(biāo)簽并為指定數(shù)組中的每個元素分配一個別名。在本例中,我們?yōu)?code>products<\/code>數(shù)組分配了別名product<\/code>。之后,我們可以使用.<\/code>運算符訪問每個數(shù)組元素中的所有屬性。我們使用endfor<\/code>標(biāo)簽來指示循環(huán)的結(jié)束。我們還可以使用..<\/code>運算符循環(huán)遍歷數(shù)字或字母。如下所示:<\/p>\n

    Hello {{ name }}<\/p><\/pre>\n

    或字母:<\/p>\n

    composer require twig\/twig<\/pre>\n

    此運算符只是range<\/code>函數(shù)的語法糖,其工作方式與本機(jī)PHPrange<\/code>函數(shù)相同。同樣有用的選項是向循環(huán)添加條件。使用條件,我們可以過濾要迭代的元素。假設(shè)我們想要迭代所有值小于250的產(chǎn)品:<\/p>\n

    \n

    條件語句<\/strong><\/p>\n

    Twig還以if<\/code>、elseif<\/code>、if not<\/code>和else<\/code>標(biāo)簽的形式提供條件語句。就像在任何編程語言中一樣,我們可以使用這些標(biāo)簽來過濾模板中的條件。假設(shè)在我們的示例中,我們只想顯示值高于500的產(chǎn)品:<\/p>\n

     'Notebook',\n        'description'   => 'Core i7',\n        'value'         =>  800.00,\n        'date_register' => '2017-06-22',\n    ],\n    [\n        'name'          => 'Mouse',\n        'description'   => 'Razer',\n        'value'         =>  125.00,\n        'date_register' => '2017-10-25',\n    ],\n    [\n        'name'          => 'Keyboard',\n        'description'   => 'Mechanical Keyboard',\n        'value'         =>  250.00,\n        'date_register' => '2017-06-23',\n    ],\n];\n\n\/\/ 渲染我們的視圖\necho $twig->render('index.html', ['products' => $products] );<\/pre>\n

    過濾器<\/strong><\/p>\n

    過濾器允許我們過濾傳遞給模板的信息以及顯示信息的格式。讓我們看看一些最常用和最重要的過濾器。Twig過濾器的完整列表可以在這里找到。<\/p>\n

    日期和date_modify<\/code><\/h3>\n

    date<\/code>過濾器將日期格式化為給定格式。正如我們在示例中看到的:<\/p>\n

    \n\n    \n        \n        Twig Example<\/title>\n    <\/head>\n    <body>
    <h1><a href="http://miracleart.cn/">国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂</a></h1>\n    <table> border=\"1\" style=\"width: 80%;\">\n        <thead>\n            <tr>\n                <td>Product<\/td>\n                <td>Description<\/td>\n                <td>Value<\/td>\n                <td>Date<\/td>\n            <\/tr>\n        <\/thead>\n        <tbody>\n            {% for product in products %}\n                <tr>\n                    <td>{{ product.name }}<\/td>\n                    <td>{{ product.description }}<\/td>\n                    <td>{{ product.value }}<\/td>\n                    <td>{{ product.date_register|date(\"m\/d\/Y\") }}<\/td>\n                <\/tr>\n            {% endfor %}\n        <\/tbody>\n    <\/table>\n    <\/body>\n<\/html><\/pre>\n<p>我們以月\/日\/年的格式顯示日期。除了<code>date<\/code>過濾器之外,我們還可以使用修飾符字符串使用<code>date_modify<\/code>過濾器更改日期。例如,如果我們想向日期添加一天,我們可以使用以下內(nèi)容:<\/p>\n<pre class='brush:php;toolbar:false;'><!DOCTYPE html>\n<html lang=\"pt-BR\">\n    <head>\n        <meta charset=\"UTF-8\">\n        <title>Tutorial Example<\/title>\n    <\/head>\n    <body>\n        {% block content %}\n        {% endblock %}\n    <\/body>\n<\/html><\/pre>\n<h3><code>format<\/code><\/h3>\n<p>通過替換所有占位符來格式化給定字符串。例如:<\/p>\n<pre class='brush:php;toolbar:false;'>{% extends \"layout.html\" %}\n\n{% block content %}\n    <table> border=\"1\" style=\"width: 80%;\">\n        <thead>\n            <tr>\n                <td>Product<\/td>\n                <td>Description<\/td>\n                <td>Value<\/td>\n                <td>Date<\/td>\n            <\/tr>\n        <\/thead>\n        <tbody>\n            {% for product in products %}\n                <tr>\n                    <td>{{ product.name }}<\/td>\n                    <td>{{ product.description }}<\/td>\n                    <td>{{ product.value }}<\/td>\n                    <td>{{ product.date_register|date(\"m\/d\/Y\") }}<\/td>\n                <\/tr>\n            {% endfor %}\n        <\/tbody>\n    <\/table>\n{% endblock %}<\/pre>\n<h3><code>striptags<\/code><\/h3>\n<p><code>striptags<\/code>過濾器去除SGML\/XML標(biāo)簽,并將相鄰的空格替換為空格:<\/p><pre class='brush:php;toolbar:false;'><?php echo \"<p> Hello \" . $name . \"<\/p>\"; ?><\/pre>\n<h3><code>escape<\/code><\/h3>\n<p><code>escape<\/code>是最重要的過濾器之一。它過濾字符串以安全地插入最終輸出中。默認(rèn)情況下,它使用HTML轉(zhuǎn)義策略,因此<\/p>\n<pre class='brush:php;toolbar:false;'><p>Hello {{ name }}<\/p><\/pre>\n<p>等效于<\/p>\n<pre class='brush:php;toolbar:false;'>composer require twig\/twig<\/pre>\n<p><code>js<\/code>、<code>css<\/code>、<code>url<\/code>和<code>html_attr<\/code>轉(zhuǎn)義策略也可使用。它們分別為Javascript、CSS、URI和HTML屬性上下文轉(zhuǎn)義字符串。<\/p>\n<p><strong>調(diào)試<\/strong><\/p>\n<p>最后,讓我們來看看調(diào)試。有時我們需要訪問模板變量的所有信息。為此,Twig具有<code>dump()<\/code>函數(shù)。此函數(shù)默認(rèn)情況下不可用。在創(chuàng)建Twig環(huán)境時,我們必須添加<code>Twig_Extension_Debug<\/code>擴(kuò)展:<\/p>\n<pre class='brush:php;toolbar:false;'><?php\n\/\/ 加載我們的自動加載器\nrequire_once __DIR__.'\/vendor\/autoload.php';\n\n\/\/ 指定我們的Twig模板位置\n$loader = new Twig_Loader_Filesystem(__DIR__.'\/templates');\n\n\/\/ 實例化我們的Twig\n$twig = new Twig_Environment($loader);<\/pre>\n<p>此步驟是必要的,這樣我們才不會意外地在生產(chǎn)服務(wù)器上泄露調(diào)試信息。配置完成后,我們只需使用<code>dump()<\/code>函數(shù)即可轉(zhuǎn)儲有關(guān)模板變量的所有信息。<\/p>\n<pre class='brush:php;toolbar:false;'><?php\nrequire_once __DIR__.'\/bootstrap.php';\n\n\/\/ 創(chuàng)建產(chǎn)品列表\n$products = [\n    [\n        'name'          => 'Notebook',\n        'description'   => 'Core i7',\n        'value'         =>  800.00,\n        'date_register' => '2017-06-22',\n    ],\n    [\n        'name'          => 'Mouse',\n        'description'   => 'Razer',\n        'value'         =>  125.00,\n        'date_register' => '2017-10-25',\n    ],\n    [\n        'name'          => 'Keyboard',\n        'description'   => 'Mechanical Keyboard',\n        'value'         =>  250.00,\n        'date_register' => '2017-06-23',\n    ],\n];\n\n\/\/ 渲染我們的視圖\necho $twig->render('index.html', ['products' => $products] );<\/pre>\n<p><strong>結(jié)論<\/strong><\/p>\n<p>希望本文能為您提供Twig基礎(chǔ)知識的堅實基礎(chǔ),并立即啟動您的項目!如果您想更深入地了解Twig,官方網(wǎng)站提供了您可以查閱的非常好的文檔和參考。您使用模板引擎嗎?您對Twig有什么看法?您會將它與Blade或Smarty等流行的替代方案進(jìn)行比較嗎?<\/p>\n<p><strong>(以下內(nèi)容為FAQ,原文已包含,此處略去)<\/strong><\/p>"}	</script>
    	
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <script>var V_PATH="/";window.onerror=function(){ return true; };</script>
    </head>
    
    <body data-commit-time="2023-12-28T14:50:12+08:00" class="editor_body body2_2">
    	<link rel="stylesheet" type="text/css" href="/static/csshw/stylehw.css">
    <header>
        <div   id="377j5v51b"   class="head">
            <div   id="377j5v51b"   class="haed_left">
                <div   id="377j5v51b"   class="haed_logo">
                    <a href="http://miracleart.cn/zh/" title="" class="haed_logo_a">
                        <img src="/static/imghw/logo.png" alt="" class="haed_logoimg">
                    </a>
                </div>
                <div   id="377j5v51b"   class="head_nav">
                    <div   id="377j5v51b"   class="head_navs">
                        <a href="javascript:;" title="社區(qū)" class="head_nava head_nava-template1">社區(qū)</a>
                        <div   class="377j5v51b"   id="dropdown-template1" style="display: none;">
                            <div   id="377j5v51b"   class="languagechoose">
                                <a href="http://miracleart.cn/zh/article.html" title="文章" class="languagechoosea on">文章</a>
                                <a href="http://miracleart.cn/zh/faq/zt" title="合集" class="languagechoosea">合集</a>
                                <a href="http://miracleart.cn/zh/wenda.html" title="問答" class="languagechoosea">問答</a>
                            </div>
                        </div>
                    </div>
    
                    <div   id="377j5v51b"   class="head_navs">
                        <a href="javascript:;" title="學(xué)習(xí)" class="head_nava head_nava-template1_1">學(xué)習(xí)</a>
                        <div   class="377j5v51b"   id="dropdown-template1_1" style="display: none;">
                            <div   id="377j5v51b"   class="languagechoose">
                                <a href="http://miracleart.cn/zh/course.html" title="課程" class="languagechoosea on">課程</a>
                                <a href="http://miracleart.cn/zh/dic/" title="編程詞典" class="languagechoosea">編程詞典</a>
                            </div>
                        </div>
                    </div>
    
                    <div   id="377j5v51b"   class="head_navs">
                        <a href="javascript:;" title="工具庫" class="head_nava head_nava-template1_2">工具庫</a>
                        <div   class="377j5v51b"   id="dropdown-template1_2" style="display: none;">
                            <div   id="377j5v51b"   class="languagechoose">
                                <a href="http://miracleart.cn/zh/toolset/development-tools" title="開發(fā)工具" class="languagechoosea on">開發(fā)工具</a>
                                <a href="http://miracleart.cn/zh/toolset/website-source-code" title="網(wǎng)站源碼" class="languagechoosea">網(wǎng)站源碼</a>
                                <a href="http://miracleart.cn/zh/toolset/php-libraries" title="PHP 庫" class="languagechoosea">PHP 庫</a>
                                <a href="http://miracleart.cn/zh/toolset/js-special-effects" title="JS特效" class="languagechoosea on">JS特效</a>
                                <a href="http://miracleart.cn/zh/toolset/website-materials" title="網(wǎng)站素材" class="languagechoosea on">網(wǎng)站素材</a>
                                <a href="http://miracleart.cn/zh/toolset/extension-plug-ins" title="擴(kuò)展插件" class="languagechoosea on">擴(kuò)展插件</a>
                            </div>
                        </div>
                    </div>
    
                    <div   id="377j5v51b"   class="head_navs">
                        <a href="http://miracleart.cn/zh/ai" title="AI工具" class="head_nava head_nava-template1_3">AI工具</a>
                    </div>
    
                    <div   id="377j5v51b"   class="head_navs">
                        <a href="javascript:;" title="休閑" class="head_nava head_nava-template1_3">休閑</a>
                        <div   class="377j5v51b"   id="dropdown-template1_3" style="display: none;">
                            <div   id="377j5v51b"   class="languagechoose">
                                <a href="http://miracleart.cn/zh/game" title="游戲下載" class="languagechoosea on">游戲下載</a>
                                <a href="http://miracleart.cn/zh/mobile-game-tutorial/" title="游戲教程" class="languagechoosea">游戲教程</a>
    
                            </div>
                        </div>
                    </div>
                </div>
            </div>
                        <div   id="377j5v51b"   class="head_search">
                    <input id="key_words"  onkeydown="if (event.keyCode == 13) searchs('zh')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value="">
                    <a href="javascript:;" title="搜索"  onclick="searchs('zh')"><img src="/static/imghw/find.png" alt="搜索"></a>
                </div>
                    <div   id="377j5v51b"   class="head_right">
                <div   id="377j5v51b"   class="haed_language">
                    <a href="javascript:;" class="layui-btn haed_language_btn">簡體中文<i class="layui-icon layui-icon-triangle-d"></i></a>
                    <div   class="377j5v51b"   id="dropdown-template" style="display: none;">
                        <div   id="377j5v51b"   class="languagechoose">
                                                    <a href="javascript:;" title="簡體中文" class="languagechoosea">簡體中文</a>
                                                    <a href="javascript:setlang('en');" title="English" class="languagechoosea">English</a>
                                                    <a href="javascript:setlang('zh-tw');" title="繁體中文" class="languagechoosea">繁體中文</a>
                                                    <a href="javascript:setlang('ja');" title="日本語" class="languagechoosea">日本語</a>
                                                    <a href="javascript:setlang('ko');" title="???" class="languagechoosea">???</a>
                                                    <a href="javascript:setlang('ms');" title="Melayu" class="languagechoosea">Melayu</a>
                                                    <a href="javascript:setlang('fr');" title="Fran?ais" class="languagechoosea">Fran?ais</a>
                                                    <a href="javascript:setlang('de');" title="Deutsch" class="languagechoosea">Deutsch</a>
                                                </div>
                    </div>
                </div>
                <span id="377j5v51b"    class="head_right_line"></span>
                                <div style="display: block;" id="login" class="haed_login ">
                        <a href="javascript:;"  title="Login" class="haed_logina ">Login</a>
                    </div>
                    <div style="display: block;" id="reg" class="head_signup login">
                        <a href="javascript:;"  title="singup" class="head_signupa">singup</a>
                    </div>
                
            </div>
        </div>
    </header>
    
    	
    	<main>
    		<div   id="377j5v51b"   class="Article_Details_main">
    			<div   id="377j5v51b"   class="Article_Details_main1">
    							<div   id="377j5v51b"   class="Article_Details_main1L">
    					<div   id="377j5v51b"   class="Article_Details_main1Lmain" id="Article_Details_main1Lmain">
    						<div   id="377j5v51b"   class="Article_Details_main1L1">目錄</div>
    						<div   id="377j5v51b"   class="Article_Details_main1L2" id="Article_Details_main1L2">
    							<!-- 左側(cè)懸浮,文章定位標(biāo)題1 id="Article_Details_main1L2s_1"-->
    															<div   id="377j5v51b"   class="Article_Details_main1L2s ">
    									<a href="#日期和-code-date-modify-code" title="日期和<code>date_modify</code>" >日期和<code>date_modify</code></a>
    								</div>
    																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
    									<a href="#code-format-code" title="<code>format</code>" ><code>format</code></a>
    								</div>
    																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
    									<a href="#code-striptags-code" title="<code>striptags</code>" ><code>striptags</code></a>
    								</div>
    																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
    									<a href="#code-escape-code" title="<code>escape</code>" ><code>escape</code></a>
    								</div>
    														</div>
    					</div>
    				</div>
    							<div   id="377j5v51b"   class="Article_Details_main1M">
    					<div   id="377j5v51b"   class="phpgenera_Details_mainL1">
    						<a href="http://miracleart.cn/zh/" title="首頁"
    							class="phpgenera_Details_mainL1a">首頁</a>
    						<img src="/static/imghw/top_right.png" alt="" />
    												<a href="http://miracleart.cn/zh/be/"
    							class="phpgenera_Details_mainL1a">后端開發(fā)</a>
    						<img src="/static/imghw/top_right.png" alt="" />
    												<a href="http://miracleart.cn/zh/php-weizijiaocheng.html"
    							class="phpgenera_Details_mainL1a">php教程</a>
    						<img src="/static/imghw/top_right.png" alt="" />
    						<span>樹枝 - 最受歡迎的獨立PHP模板引擎</span>
    					</div>
    					
    					<div   id="377j5v51b"   class="Articlelist_txts">
    						<div   id="377j5v51b"   class="Articlelist_txts_info">
    							<h1 class="Articlelist_txts_title">樹枝 - 最受歡迎的獨立PHP模板引擎</h1>
    							<div   id="377j5v51b"   class="Articlelist_txts_info_head">
    								<div   id="377j5v51b"   class="author_info">
    									<a href="http://miracleart.cn/zh/member/1468493.html"  class="author_avatar">
    									<img class="lazy"  data-src="https://img.php.cn/upload/avatar/000/000/001/66ea8139b1640968.png" src="/static/imghw/default1.png" alt="Lisa Kudrow">
    									</a>
    									<div   id="377j5v51b"   class="author_detail">
    																			<a href="http://miracleart.cn/zh/member/1468493.html" class="author_name">Lisa Kudrow</a>
                                    										</div>
    								</div>
                    			</div>
    							<span id="377j5v51b"    class="Articlelist_txts_time">Feb 09, 2025 am	 09:07 AM</span>
    														
    						</div>
    					</div>
    					<hr />
    					<div   id="377j5v51b"   class="article_main php-article">
    						<div   id="377j5v51b"   class="article-list-left detail-content-wrap content">
    						<ins class="adsbygoogle"
    							style="display:block; text-align:center;"
    							data-ad-layout="in-article"
    							data-ad-format="fluid"
    							data-ad-client="ca-pub-5902227090019525"
    							data-ad-slot="3461856641">
    						</ins>
    						
    
    					<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173906323392943.jpg" class="lazy" alt="Twig - the Most Popular Stand-Alone PHP Template Engine "></p>
    <p><strong>Twig:一款流行的PHP模板引擎</strong></p>
    <p>Twig是由Sensio Labs開發(fā)的PHP流行模板引擎,它簡化了PHP代碼,并增加了安全和調(diào)試等功能。Twig同時作用于項目的frontend和backend,可以從兩個角度來看:模板設(shè)計師的Twig和開發(fā)者的Twig。Twig使用名為<code>Environment</code>的核心對象來存儲配置、擴(kuò)展,并從文件系統(tǒng)或其他位置加載模板。Twig支持嵌套模板(塊),避免模板中元素重復(fù),并能緩存編譯后的模板以加快后續(xù)請求速度。Twig支持條件語句、循環(huán)和過濾器來控制模板中信息的顯示,并提供調(diào)試功能來轉(zhuǎn)儲模板變量的所有信息。</p>
    <p><em>本文由Wern Ancheta同行評審。感謝所有SitePoint的同行評審員,使SitePoint的內(nèi)容達(dá)到最佳狀態(tài)!</em></p>
    <hr>
    <p>Twig是PHP的模板引擎。但是,PHP本身不是模板引擎嗎?是的,也不是!盡管PHP最初是作為模板引擎,但它的發(fā)展并非如此,雖然我們?nèi)匀豢梢詫⑵溆米髂0逡?,請問您更喜歡哪個版本的“Hello world”:</p>
    <pre class='brush:php;toolbar:false;'><?php echo "<p> Hello " . $name . "</p>"; ?></pre>
    <p>還是</p>
    <pre class='brush:php;toolbar:false;'><p>Hello {{ name }}</p></pre>
    <p>PHP是一種冗長的語言,在嘗試輸出HTML內(nèi)容時,這種冗長性會被放大?,F(xiàn)代模板系統(tǒng)將消除部分冗長性,并在其之上增加相當(dāng)多的功能。諸如安全和調(diào)試功能之類的特性是現(xiàn)代模板引擎的支柱。今天,我們將重點介紹Twig。</p>
    <p><img src="/static/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/173906323392943.jpg"  class="lazy" alt="Twig - the Most Popular Stand-Alone PHP Template Engine " /></p>
    <p>Twig是由Sensio Labs(Blackfire和Symfony的開發(fā)公司)創(chuàng)建的模板引擎。讓我們來看看它的主要優(yōu)勢以及如何在項目中使用它。</p>
    <p><strong>安裝</strong></p>
    <p>安裝Twig有兩種方法。我們可以使用其網(wǎng)站上提供的tar包,或者像我們一直做的那樣,使用Composer。</p>
    <pre class='brush:php;toolbar:false;'>composer require twig/twig</pre>
    <p><em>我們假設(shè)您正在運行已設(shè)置PHP并全局安裝Composer的環(huán)境。最好的方法是使用Homestead Improved——它可以讓您在5分鐘內(nèi)在與我們使用的完全相同的機(jī)器上開始使用,這樣我們就能在同一頁面上。如果您想了解有關(guān)PHP環(huán)境的更多信息,我們這里有一本關(guān)于此的優(yōu)秀付費書籍可供購買。</em></p>
    <p>在我們繼續(xù)之前,我們需要先澄清一些事情。作為模板引擎,Twig同時作用于項目的frontend和backend。因此,我們可以從兩個不同的角度來看待Twig:模板設(shè)計師的Twig和開發(fā)者的Twig。一方面,我們準(zhǔn)備所有需要的數(shù)據(jù);另一方面,我們呈現(xiàn)所有這些數(shù)據(jù)。</p>
    <p><strong>基本用法</strong></p><p>為了舉例說明Twig的基本用法,讓我們創(chuàng)建一個簡單的項目。首先,我們需要引導(dǎo)Twig。讓我們創(chuàng)建一個包含以下內(nèi)容的<code>bootstrap.php</code>文件:</p>
    <pre class='brush:php;toolbar:false;'><?php echo "<p> Hello " . $name . "</p>"; ?></pre>
    <p>Twig使用名為<code>Environment</code>的核心對象。此類的實例用于存儲配置、擴(kuò)展,并從文件系統(tǒng)或其他位置加載模板。在我們的Twig實例引導(dǎo)后,我們可以繼續(xù)創(chuàng)建一個<code>index.php</code>文件,在其中加載一些數(shù)據(jù)并將其傳遞給Twig模板。</p>
    <pre class='brush:php;toolbar:false;'><p>Hello {{ name }}</p></pre>
    <p>這是一個簡單的示例;我們正在創(chuàng)建一個包含產(chǎn)品的數(shù)組,例如我們的機(jī)械鍵盤,我們可以在模板中使用它。然后,我們使用<code>render()</code>方法,它接受模板名稱(這是我們之前定義的模板文件夾中的一個文件)以及我們要傳遞給模板的數(shù)據(jù)。為了完成我們的示例,讓我們進(jìn)入我們的<code>/templates</code>文件夾并創(chuàng)建一個<code>index.html</code>文件。首先,讓我們看看模板本身。</p>
    <pre class='brush:php;toolbar:false;'>composer require twig/twig</pre>
    <p>在瀏覽器中打開<code>index.php</code>(訪問localhost或homestead.app,具體取決于您如何設(shè)置主機(jī)和服務(wù)器)現(xiàn)在應(yīng)該會顯示以下屏幕:</p>
    <p><img src="/static/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/173906323463936.jpg"  class="lazy" alt="Twig - the Most Popular Stand-Alone PHP Template Engine " /></p>
    <p>但是讓我們回到并仔細(xì)看看我們的模板代碼。有兩種類型的分隔符:<code>{{ ... }}</code>用于打印表達(dá)式或操作的結(jié)果,而<code>{% ... %}</code>用于執(zhí)行諸如條件語句和循環(huán)之類的語句。這些分隔符是Twig的主要語言結(jié)構(gòu),Twig使用它們來“告知”模板它必須呈現(xiàn)Twig元素。</p>
    <p><strong>(以下內(nèi)容與原文類似,但做了部分語句調(diào)整和段落劃分,并保持了圖片位置不變)</strong></p>
    <p><strong>布局</strong></p>
    <p>為了避免在模板中重復(fù)元素(如頁眉和頁腳),Twig允許我們將模板嵌套在模板中,這些被稱為塊。為了舉例說明這一點,讓我們將實際內(nèi)容與示例中的HTML定義分開。讓我們創(chuàng)建一個新的HTML文件并將其命名為<code>layout.html</code>:</p>
    <pre class='brush:php;toolbar:false;'><?php
    // 加載我們的自動加載器
    require_once __DIR__.'/vendor/autoload.php';
    
    // 指定我們的Twig模板位置
    $loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
    
    // 實例化我們的Twig
    $twig = new Twig_Environment($loader);</pre>
    <p>我們創(chuàng)建了一個名為<code>content</code>的塊。我們的意思是,每個從<code>layout.html</code>擴(kuò)展的模板都可以實現(xiàn)一個<code>content</code>塊,該塊將顯示在該位置。這樣,我們可以多次重用布局而無需重寫它。在本例中,<code>index.html</code>文件現(xiàn)在如下所示:</p>
    <pre class='brush:php;toolbar:false;'><?php
    require_once __DIR__.'/bootstrap.php';
    
    // 創(chuàng)建產(chǎn)品列表
    $products = [
        [
            'name'          => 'Notebook',
            'description'   => 'Core i7',
            'value'         =>  800.00,
            'date_register' => '2017-06-22',
        ],
        [
            'name'          => 'Mouse',
            'description'   => 'Razer',
            'value'         =>  125.00,
            'date_register' => '2017-10-25',
        ],
        [
            'name'          => 'Keyboard',
            'description'   => 'Mechanical Keyboard',
            'value'         =>  250.00,
            'date_register' => '2017-06-23',
        ],
    ];
    
    // 渲染我們的視圖
    echo $twig->render('index.html', ['products' => $products] );</pre>
    <p>Twig還允許我們只渲染單個塊。為此,我們需要首先加載模板,然后渲染塊。</p>
    <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
    <html lang="pt-BR">
        <head>
            <meta charset="UTF-8">
            <title>Twig Example</title>
        </head>
        <body>
        <table> border="1" style="width: 80%;">
            <thead>
                <tr>
                    <td>Product</td>
                    <td>Description</td>
                    <td>Value</td>
                    <td>Date</td>
                </tr>
            </thead>
            <tbody>
                {% for product in products %}
                    <tr>
                        <td>{{ product.name }}</td>
                        <td>{{ product.description }}</td>
                        <td>{{ product.value }}</td>
                        <td>{{ product.date_register|date("m/d/Y") }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        </body>
    </html></pre>
    <p>此時,我們?nèi)匀粨碛邢嗤捻撁?,但我們通過分離上下文塊來降低了它的復(fù)雜性。</p>
    <p><strong>緩存</strong></p><p><code>Environment</code>對象不僅可以用于加載模板。如果我們使用關(guān)聯(lián)目錄的<code>cache</code>選項傳遞,Twig將緩存編譯后的模板,從而避免在后續(xù)請求中解析模板。編譯后的模板將存儲在我們提供的目錄中。請注意,這是編譯模板的緩存,而不是已評估的模板的緩存。這意味著Twig將解析、編譯并保存模板文件。所有后續(xù)請求仍然需要評估模板,但第一步已經(jīng)為您完成。讓我們通過編輯<code>bootstrap.php</code>文件來緩存示例中的模板:</p>
    <pre class='brush:php;toolbar:false;'><?php echo "<p> Hello " . $name . "</p>"; ?></pre>
    <p><strong>(以下內(nèi)容與原文類似,但做了部分語句調(diào)整和段落劃分,并保持了圖片位置不變)</strong></p>
    <p><strong>循環(huán)</strong></p>
    <p>在我們的示例中,我們已經(jīng)看到了如何使用Twig進(jìn)行循環(huán)?;旧?,我們使用<code>for</code>標(biāo)簽并為指定數(shù)組中的每個元素分配一個別名。在本例中,我們?yōu)?code>products</code>數(shù)組分配了別名<code>product</code>。之后,我們可以使用<code>.</code>運算符訪問每個數(shù)組元素中的所有屬性。我們使用<code>endfor</code>標(biāo)簽來指示循環(huán)的結(jié)束。我們還可以使用<code>..</code>運算符循環(huán)遍歷數(shù)字或字母。如下所示:</p>
    <pre class='brush:php;toolbar:false;'><p>Hello {{ name }}</p></pre>
    <p>或字母:</p>
    <pre class='brush:php;toolbar:false;'>composer require twig/twig</pre>
    <p>此運算符只是<code>range</code>函數(shù)的語法糖,其工作方式與本機(jī)PHP<code>range</code>函數(shù)相同。同樣有用的選項是向循環(huán)添加條件。使用條件,我們可以過濾要迭代的元素。假設(shè)我們想要迭代所有值小于250的產(chǎn)品:</p>
    <pre class='brush:php;toolbar:false;'><?php
    // 加載我們的自動加載器
    require_once __DIR__.'/vendor/autoload.php';
    
    // 指定我們的Twig模板位置
    $loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
    
    // 實例化我們的Twig
    $twig = new Twig_Environment($loader);</pre>
    <p><strong>條件語句</strong></p>
    <p>Twig還以<code>if</code>、<code>elseif</code>、<code>if not</code>和<code>else</code>標(biāo)簽的形式提供條件語句。就像在任何編程語言中一樣,我們可以使用這些標(biāo)簽來過濾模板中的條件。假設(shè)在我們的示例中,我們只想顯示值高于500的產(chǎn)品:</p>
    <pre class='brush:php;toolbar:false;'><?php
    require_once __DIR__.'/bootstrap.php';
    
    // 創(chuàng)建產(chǎn)品列表
    $products = [
        [
            'name'          => 'Notebook',
            'description'   => 'Core i7',
            'value'         =>  800.00,
            'date_register' => '2017-06-22',
        ],
        [
            'name'          => 'Mouse',
            'description'   => 'Razer',
            'value'         =>  125.00,
            'date_register' => '2017-10-25',
        ],
        [
            'name'          => 'Keyboard',
            'description'   => 'Mechanical Keyboard',
            'value'         =>  250.00,
            'date_register' => '2017-06-23',
        ],
    ];
    
    // 渲染我們的視圖
    echo $twig->render('index.html', ['products' => $products] );</pre>
    <p><strong>過濾器</strong></p>
    <p>過濾器允許我們過濾傳遞給模板的信息以及顯示信息的格式。讓我們看看一些最常用和最重要的過濾器。Twig過濾器的完整列表可以在這里找到。</p>
    <h3 id="日期和-code-date-modify-code">日期和<code>date_modify</code></h3>
    <p><code>date</code>過濾器將日期格式化為給定格式。正如我們在示例中看到的:</p>
    <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
    <html lang="pt-BR">
        <head>
            <meta charset="UTF-8">
            <title>Twig Example</title>
        </head>
        <body>
        <table> border="1" style="width: 80%;">
            <thead>
                <tr>
                    <td>Product</td>
                    <td>Description</td>
                    <td>Value</td>
                    <td>Date</td>
                </tr>
            </thead>
            <tbody>
                {% for product in products %}
                    <tr>
                        <td>{{ product.name }}</td>
                        <td>{{ product.description }}</td>
                        <td>{{ product.value }}</td>
                        <td>{{ product.date_register|date("m/d/Y") }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        </body>
    </html></pre>
    <p>我們以月/日/年的格式顯示日期。除了<code>date</code>過濾器之外,我們還可以使用修飾符字符串使用<code>date_modify</code>過濾器更改日期。例如,如果我們想向日期添加一天,我們可以使用以下內(nèi)容:</p>
    <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
    <html lang="pt-BR">
        <head>
            <meta charset="UTF-8">
            <title>Tutorial Example</title>
        </head>
        <body>
            {% block content %}
            {% endblock %}
        </body>
    </html></pre>
    <h3 id="code-format-code"><code>format</code></h3>
    <p>通過替換所有占位符來格式化給定字符串。例如:</p>
    <pre class='brush:php;toolbar:false;'>{% extends "layout.html" %}
    
    {% block content %}
        <table> border="1" style="width: 80%;">
            <thead>
                <tr>
                    <td>Product</td>
                    <td>Description</td>
                    <td>Value</td>
                    <td>Date</td>
                </tr>
            </thead>
            <tbody>
                {% for product in products %}
                    <tr>
                        <td>{{ product.name }}</td>
                        <td>{{ product.description }}</td>
                        <td>{{ product.value }}</td>
                        <td>{{ product.date_register|date("m/d/Y") }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endblock %}</pre>
    <h3 id="code-striptags-code"><code>striptags</code></h3>
    <p><code>striptags</code>過濾器去除SGML/XML標(biāo)簽,并將相鄰的空格替換為空格:</p><pre class='brush:php;toolbar:false;'><?php echo "<p> Hello " . $name . "</p>"; ?></pre>
    <h3 id="code-escape-code"><code>escape</code></h3>
    <p><code>escape</code>是最重要的過濾器之一。它過濾字符串以安全地插入最終輸出中。默認(rèn)情況下,它使用HTML轉(zhuǎn)義策略,因此</p>
    <pre class='brush:php;toolbar:false;'><p>Hello {{ name }}</p></pre>
    <p>等效于</p>
    <pre class='brush:php;toolbar:false;'>composer require twig/twig</pre>
    <p><code>js</code>、<code>css</code>、<code>url</code>和<code>html_attr</code>轉(zhuǎn)義策略也可使用。它們分別為Javascript、CSS、URI和HTML屬性上下文轉(zhuǎn)義字符串。</p>
    <p><strong>調(diào)試</strong></p>
    <p>最后,讓我們來看看調(diào)試。有時我們需要訪問模板變量的所有信息。為此,Twig具有<code>dump()</code>函數(shù)。此函數(shù)默認(rèn)情況下不可用。在創(chuàng)建Twig環(huán)境時,我們必須添加<code>Twig_Extension_Debug</code>擴(kuò)展:</p>
    <pre class='brush:php;toolbar:false;'><?php
    // 加載我們的自動加載器
    require_once __DIR__.'/vendor/autoload.php';
    
    // 指定我們的Twig模板位置
    $loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
    
    // 實例化我們的Twig
    $twig = new Twig_Environment($loader);</pre>
    <p>此步驟是必要的,這樣我們才不會意外地在生產(chǎn)服務(wù)器上泄露調(diào)試信息。配置完成后,我們只需使用<code>dump()</code>函數(shù)即可轉(zhuǎn)儲有關(guān)模板變量的所有信息。</p>
    <pre class='brush:php;toolbar:false;'><?php
    require_once __DIR__.'/bootstrap.php';
    
    // 創(chuàng)建產(chǎn)品列表
    $products = [
        [
            'name'          => 'Notebook',
            'description'   => 'Core i7',
            'value'         =>  800.00,
            'date_register' => '2017-06-22',
        ],
        [
            'name'          => 'Mouse',
            'description'   => 'Razer',
            'value'         =>  125.00,
            'date_register' => '2017-10-25',
        ],
        [
            'name'          => 'Keyboard',
            'description'   => 'Mechanical Keyboard',
            'value'         =>  250.00,
            'date_register' => '2017-06-23',
        ],
    ];
    
    // 渲染我們的視圖
    echo $twig->render('index.html', ['products' => $products] );</pre>
    <p><strong>結(jié)論</strong></p>
    <p>希望本文能為您提供Twig基礎(chǔ)知識的堅實基礎(chǔ),并立即啟動您的項目!如果您想更深入地了解Twig,官方網(wǎng)站提供了您可以查閱的非常好的文檔和參考。您使用模板引擎嗎?您對Twig有什么看法?您會將它與Blade或Smarty等流行的替代方案進(jìn)行比較嗎?</p>
    <p><strong>(以下內(nèi)容為FAQ,原文已包含,此處略去)</strong></p><p>以上是樹枝 - 最受歡迎的獨立PHP模板引擎的詳細(xì)內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!</p>
    
    
    						</div>
    					</div>
    					<div   id="377j5v51b"   class="wzconShengming_sp">
    						<div   id="377j5v51b"   class="bzsmdiv_sp">本站聲明</div>
    						<div>本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn</div>
    					</div>
    				</div>
    
    				<ins class="adsbygoogle"
         style="display:block"
         data-ad-format="autorelaxed"
         data-ad-client="ca-pub-5902227090019525"
         data-ad-slot="2507867629"></ins>
    
    
    
    				<div   id="377j5v51b"   class="AI_ToolDetails_main4sR">
    
    
    				<ins class="adsbygoogle"
            style="display:block"
            data-ad-client="ca-pub-5902227090019525"
            data-ad-slot="3653428331"
            data-ad-format="auto"
            data-full-width-responsive="true"></ins>
        
    
    
    					<!-- <div   id="377j5v51b"   class="phpgenera_Details_mainR4">
    						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
    							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
    								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    									src="/static/imghw/hotarticle2.png" alt="" />
    								<h2>熱門文章</h2>
    							</div>
    							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819578.html" title="如何修復(fù)KB5060533無法在Windows 10中安裝?" class="phpgenera_Details_mainR4_bottom_title">如何修復(fù)KB5060533無法在Windows 10中安裝?</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>4 周前</span>
    										<span>By DDD</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819730.html" title="沙丘:覺醒 - 在哪里獲得絕緣織物" class="phpgenera_Details_mainR4_bottom_title">沙丘:覺醒 - 在哪里獲得絕緣織物</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>4 周前</span>
    										<span>By Jack chen</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819016.html" title="Gmail登錄:如何注冊,登錄或登錄Gmail -Minitool" class="phpgenera_Details_mainR4_bottom_title">Gmail登錄:如何注冊,登錄或登錄Gmail -Minitool</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>1 個月前</span>
    										<span>By Jack chen</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819994.html" title="如何修復(fù)KB5060999無法在Windows 11中安裝?" class="phpgenera_Details_mainR4_bottom_title">如何修復(fù)KB5060999無法在Windows 11中安裝?</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>3 周前</span>
    										<span>By DDD</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819536.html" title="污染的公會指南:阿瓦隆的淪陷" class="phpgenera_Details_mainR4_bottom_title">污染的公會指南:阿瓦隆的淪陷</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>4 周前</span>
    										<span>By Jack chen</span>
    									</div>
    								</div>
    														</div>
    							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
    								<a href="http://miracleart.cn/zh/article.html">顯示更多</a>
    							</div>
    						</div>
    					</div> -->
    
    
    											<div   id="377j5v51b"   class="phpgenera_Details_mainR3">
    							<div   id="377j5v51b"   class="phpmain1_4R_readrank">
    								<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/hottools2.png" alt="" />
    									<h2>熱AI工具</h2>
    								</div>
    								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_bottom">
    																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title">
    													<h3>Undress AI Tool</h3>
    												</a>
    												<p>免費脫衣服圖片</p>
    											</div>
    										</div>
    																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title">
    													<h3>Undresser.AI Undress</h3>
    												</a>
    												<p>人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片</p>
    											</div>
    										</div>
    																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title">
    													<h3>AI Clothes Remover</h3>
    												</a>
    												<p>用于從照片中去除衣服的在線人工智能工具。</p>
    											</div>
    										</div>
    																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title">
    													<h3>Clothoff.io</h3>
    												</a>
    												<p>AI脫衣機(jī)</p>
    											</div>
    										</div>
    																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173414504068133.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Video Face Swap" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title">
    													<h3>Video Face Swap</h3>
    												</a>
    												<p>使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!</p>
    											</div>
    										</div>
    																</div>
    								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
    									<a href="http://miracleart.cn/zh/ai">顯示更多</a>
    								</div>
    							</div>
    						</div>
    					
    
    
    					<div   id="377j5v51b"   class="phpgenera_Details_mainR4">
    						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
    							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
    								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    									src="/static/imghw/hotarticle2.png" alt="" />
    								<h2>熱門文章</h2>
    							</div>
    							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819578.html" title="如何修復(fù)KB5060533無法在Windows 10中安裝?" class="phpgenera_Details_mainR4_bottom_title">如何修復(fù)KB5060533無法在Windows 10中安裝?</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>4 周前</span>
    										<span>By DDD</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819730.html" title="沙丘:覺醒 - 在哪里獲得絕緣織物" class="phpgenera_Details_mainR4_bottom_title">沙丘:覺醒 - 在哪里獲得絕緣織物</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>4 周前</span>
    										<span>By Jack chen</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819016.html" title="Gmail登錄:如何注冊,登錄或登錄Gmail -Minitool" class="phpgenera_Details_mainR4_bottom_title">Gmail登錄:如何注冊,登錄或登錄Gmail -Minitool</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>1 個月前</span>
    										<span>By Jack chen</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819994.html" title="如何修復(fù)KB5060999無法在Windows 11中安裝?" class="phpgenera_Details_mainR4_bottom_title">如何修復(fù)KB5060999無法在Windows 11中安裝?</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>3 周前</span>
    										<span>By DDD</span>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/1796819536.html" title="污染的公會指南:阿瓦隆的淪陷" class="phpgenera_Details_mainR4_bottom_title">污染的公會指南:阿瓦隆的淪陷</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<span>4 周前</span>
    										<span>By Jack chen</span>
    									</div>
    								</div>
    														</div>
    							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
    								<a href="http://miracleart.cn/zh/article.html">顯示更多</a>
    							</div>
    						</div>
    					</div>
    
    
    											<div   id="377j5v51b"   class="phpgenera_Details_mainR3">
    							<div   id="377j5v51b"   class="phpmain1_4R_readrank">
    								<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/hottools2.png" alt="" />
    									<h2>熱工具</h2>
    								</div>
    								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_bottom">
    																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="記事本++7.3.1" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_title">
    													<h3>記事本++7.3.1</h3>
    												</a>
    												<p>好用且免費的代碼編輯器</p>
    											</div>
    										</div>
    																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/toolset/development-tools/93" title="SublimeText3漢化版" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3漢化版" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/toolset/development-tools/93" title="SublimeText3漢化版" class="phpmain_tab2_mids_title">
    													<h3>SublimeText3漢化版</h3>
    												</a>
    												<p>中文版,非常好用</p>
    											</div>
    										</div>
    																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="禪工作室 13.0.1" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_title">
    													<h3>禪工作室 13.0.1</h3>
    												</a>
    												<p>功能強(qiáng)大的PHP集成開發(fā)環(huán)境</p>
    											</div>
    										</div>
    																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title">
    													<h3>Dreamweaver CS6</h3>
    												</a>
    												<p>視覺化網(wǎng)頁開發(fā)工具</p>
    											</div>
    										</div>
    																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
    											<a href="http://miracleart.cn/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_top_img">
    												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Mac版" />
    											</a>
    											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
    												<a href="http://miracleart.cn/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_title">
    													<h3>SublimeText3 Mac版</h3>
    												</a>
    												<p>神級代碼編輯軟件(SublimeText3)</p>
    											</div>
    										</div>
    																	</div>
    								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
    									<a href="http://miracleart.cn/zh/ai">顯示更多</a>
    								</div>
    							</div>
    						</div>
    										
    
    					
    					<div   id="377j5v51b"   class="phpgenera_Details_mainR4">
    						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
    							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
    								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    									src="/static/imghw/hotarticle2.png" alt="" />
    								<h2>熱門話題</h2>
    							</div>
    							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/gmailyxdlrkzn" title="gmail郵箱登陸入口在哪里" class="phpgenera_Details_mainR4_bottom_title">gmail郵箱登陸入口在哪里</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/eyess.png" alt="" />
    											<span>8517</span>
    										</div>
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/tiezi.png" alt="" />
    											<span>17</span>
    										</div>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/java-tutorial" title="Java教程" class="phpgenera_Details_mainR4_bottom_title">Java教程</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/eyess.png" alt="" />
    											<span>1744</span>
    										</div>
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/tiezi.png" alt="" />
    											<span>16</span>
    										</div>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/cakephp-tutor" title="CakePHP 教程" class="phpgenera_Details_mainR4_bottom_title">CakePHP 教程</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/eyess.png" alt="" />
    											<span>1596</span>
    										</div>
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/tiezi.png" alt="" />
    											<span>56</span>
    										</div>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/laravel-tutori" title="Laravel 教程" class="phpgenera_Details_mainR4_bottom_title">Laravel 教程</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/eyess.png" alt="" />
    											<span>1537</span>
    										</div>
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/tiezi.png" alt="" />
    											<span>28</span>
    										</div>
    									</div>
    								</div>
    															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
    									<a href="http://miracleart.cn/zh/faq/php-tutorial" title="PHP教程" class="phpgenera_Details_mainR4_bottom_title">PHP教程</a>
    									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/eyess.png" alt="" />
    											<span>1396</span>
    										</div>
    										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
    											<img src="/static/imghw/tiezi.png" alt="" />
    											<span>31</span>
    										</div>
    									</div>
    								</div>
    														</div>
    							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
    								<a href="http://miracleart.cn/zh/faq/zt">顯示更多</a>
    							</div>
    						</div>
    					</div>
    				</div>
    			</div>
    							<div   id="377j5v51b"   class="Article_Details_main2">
    					<div   id="377j5v51b"   class="phpgenera_Details_mainL4">
    						<div   id="377j5v51b"   class="phpmain1_2_top">
    							<a href="javascript:void(0);" class="phpmain1_2_top_title">Related knowledge<img
    									src="/static/imghw/index2_title2.png" alt="" /></a>
    						</div>
    						<div   id="377j5v51b"   class="phpgenera_Details_mainL4_info">
    
    													<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796820395.html" title="對基于PHP的API進(jìn)行版本控制的最佳實踐是什么?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/174983207178259.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="對基于PHP的API進(jìn)行版本控制的最佳實踐是什么?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796820395.html" title="對基于PHP的API進(jìn)行版本控制的最佳實踐是什么?" class="phphistorical_Version2_mids_title">對基于PHP的API進(jìn)行版本控制的最佳實踐是什么?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 14, 2025 am	 12:27 AM</span>
    								<p class="Articlelist_txts_p">基于toversionaphp,useUrl deuseUrl specteringforclarityAndEsofRouting,單獨的codetoavoidConflicts,dremecateOldVersionswithClearCommunication,andConsiderCustomHeadeSerlySerallyWhennEnncelsy.startbyplacingtheversionIntheUrl(E.G.,epi/api/v</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796822204.html" title="如何在PHP中實施身份驗證和授權(quán)?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175035261135357.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在PHP中實施身份驗證和授權(quán)?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796822204.html" title="如何在PHP中實施身份驗證和授權(quán)?" class="phphistorical_Version2_mids_title">如何在PHP中實施身份驗證和授權(quán)?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 20, 2025 am	 01:03 AM</span>
    								<p class="Articlelist_txts_p">tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796820386.html" title="PHP中的程序和面向?qū)ο蟮木幊谭独g有什么區(qū)別?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/174983193177803.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP中的程序和面向?qū)ο蟮木幊谭独g有什么區(qū)別?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796820386.html" title="PHP中的程序和面向?qū)ο蟮木幊谭独g有什么區(qū)別?" class="phphistorical_Version2_mids_title">PHP中的程序和面向?qū)ο蟮木幊谭独g有什么區(qū)別?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 14, 2025 am	 12:25 AM</span>
    								<p class="Articlelist_txts_p">procemal and object-tiriendedprogromming(oop)inphpdiffersimplessintustructure,可重復(fù)使用性和datahandling.1.procedural-Progrogursmingusesfunctimesfunctionsormanized sequalized sequalized sequiential,poiperforsmallscripts.2.OpporganizesCodeOrganizescodeOdeIntsocloceSandObjects,ModelingReal-Worlden-Worlden</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796820387.html" title="PHP中有哪些弱參考(弱圖),何時有用?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/174983195046134.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP中有哪些弱參考(弱圖),何時有用?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796820387.html" title="PHP中有哪些弱參考(弱圖),何時有用?" class="phphistorical_Version2_mids_title">PHP中有哪些弱參考(弱圖),何時有用?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 14, 2025 am	 12:25 AM</span>
    								<p class="Articlelist_txts_p">PHPdoesnothaveabuilt-inWeakMapbutoffersWeakReferenceforsimilarfunctionality.1.WeakReferenceallowsholdingreferenceswithoutpreventinggarbagecollection.2.Itisusefulforcaching,eventlisteners,andmetadatawithoutaffectingobjectlifecycles.3.YoucansimulateaWe</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796821722.html" title="如何在PHP中安全地處理文件上傳?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175026630154351.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在PHP中安全地處理文件上傳?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796821722.html" title="如何在PHP中安全地處理文件上傳?" class="phphistorical_Version2_mids_title">如何在PHP中安全地處理文件上傳?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 19, 2025 am	 01:05 AM</span>
    								<p class="Articlelist_txts_p">要安全處理PHP中的文件上傳,核心在于驗證文件類型、重命名文件并限制權(quán)限。1.使用finfo_file()檢查真實MIME類型,僅允許特定類型如image/jpeg;2.用uniqid()生成隨機(jī)文件名,存儲至非Web根目錄;3.通過php.ini和HTML表單限制文件大小,設(shè)置目錄權(quán)限為0755;4.使用ClamAV掃描惡意軟件,增強(qiáng)安全性。這些步驟有效防止安全漏洞,確保文件上傳過程安全可靠。</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796821728.html" title="如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進(jìn)行交互?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175026645186884.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進(jìn)行交互?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796821728.html" title="如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進(jìn)行交互?" class="phphistorical_Version2_mids_title">如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進(jìn)行交互?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 19, 2025 am	 01:07 AM</span>
    								<p class="Articlelist_txts_p">是的,PHP可以通過特定擴(kuò)展或庫與MongoDB和Redis等NoSQL數(shù)據(jù)庫交互。首先,使用MongoDBPHP驅(qū)動(通過PECL或Composer安裝)創(chuàng)建客戶端實例并操作數(shù)據(jù)庫及集合,支持插入、查詢、聚合等操作;其次,使用Predis庫或phpredis擴(kuò)展連接Redis,執(zhí)行鍵值設(shè)置與獲取,推薦phpredis用于高性能場景,Predis則便于快速部署;兩者均適用于生產(chǎn)環(huán)境且文檔完善。</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796821729.html" title="PHP中==(松散比較)和===(嚴(yán)格的比較)之間有什么區(qū)別?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175026647097920.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP中==(松散比較)和===(嚴(yán)格的比較)之間有什么區(qū)別?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796821729.html" title="PHP中==(松散比較)和===(嚴(yán)格的比較)之間有什么區(qū)別?" class="phphistorical_Version2_mids_title">PHP中==(松散比較)和===(嚴(yán)格的比較)之間有什么區(qū)別?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 19, 2025 am	 01:07 AM</span>
    								<p class="Articlelist_txts_p">在PHP中,==與===的主要區(qū)別在于類型檢查的嚴(yán)格程度。==在比較前會進(jìn)行類型轉(zhuǎn)換,例如5=="5"返回true,而===要求值和類型都相同才會返回true,例如5==="5"返回false。使用場景上,===更安全應(yīng)優(yōu)先使用,==僅在需要類型轉(zhuǎn)換時使用。</p>
    							</div>
    														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
    								<a href="http://miracleart.cn/zh/faq/1796821933.html" title="如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作?" class="phphistorical_Version2_mids_img">
    									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
    										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175032439158710.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作?" />
    								</a>
    								<a href="http://miracleart.cn/zh/faq/1796821933.html" title="如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作?" class="phphistorical_Version2_mids_title">如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作?</a>
    								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 19, 2025 pm	 05:13 PM</span>
    								<p class="Articlelist_txts_p">PHP中使用基本數(shù)學(xué)運算的方法如下:1.加法用 號,支持整數(shù)和浮點數(shù),也可用于變量,字符串?dāng)?shù)字會自動轉(zhuǎn)換但不推薦依賴;2.減法用-號,變量同理,類型轉(zhuǎn)換同樣適用;3.乘法用*號,適用于數(shù)字及類似字符串;4.除法用/號,需避免除以零,并注意結(jié)果可能是浮點數(shù);5.取模用%號,可用于判斷奇偶數(shù),處理負(fù)數(shù)時余數(shù)符號與被除數(shù)一致。正確使用這些運算符的關(guān)鍵在于確保數(shù)據(jù)類型清晰并處理好邊界情況。</p>
    							</div>
    													</div>
    
    													<a href="http://miracleart.cn/zh/be/" class="phpgenera_Details_mainL4_botton">
    								<span>See all articles</span>
    								<img src="/static/imghw/down_right.png" alt="" />
    							</a>
    											</div>
    				</div>
    					</div>
    	</main>
    	<footer>
        <div   id="377j5v51b"   class="footer">
            <div   id="377j5v51b"   class="footertop">
                <img src="/static/imghw/logo.png" alt="">
                <p>公益在線PHP培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!</p>
            </div>
            <div   id="377j5v51b"   class="footermid">
                <a href="http://miracleart.cn/zh/about/us.html">關(guān)于我們</a>
                <a href="http://miracleart.cn/zh/about/disclaimer.html">免責(zé)聲明</a>
                <a href="http://miracleart.cn/zh/update/article_0_1.html">Sitemap</a>
            </div>
            <div   id="377j5v51b"   class="footerbottom">
                <p>
                    ? php.cn All rights reserved
                </p>
            </div>
        </div>
    </footer>
    
    <input type="hidden" id="verifycode" value="/captcha.html">
    
    
    
    
    		<link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css?2' type='text/css' media='all' />
    	
    	
    	
    	
    	
    
    	
    	
    
    
    
    
    
    
    <footer>
    <div class="friendship-link">
    <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p>
    <a href="http://miracleart.cn/" title="国产av日韩一区二区三区精品">国产av日韩一区二区三区精品</a>
    
    <div class="friend-links">
    
    
    </div>
    </div>
    
    </footer>
    
    
    <script>
    (function(){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
    </script>
    </body><div id="sibua" class="pl_css_ganrao" style="display: none;"><small id="sibua"><bdo id="sibua"></bdo></small><sub id="sibua"><b id="sibua"><small id="sibua"></small></b></sub><small id="sibua"><form id="sibua"><acronym id="sibua"></acronym></form></small><strike id="sibua"><tfoot id="sibua"><b id="sibua"><small id="sibua"></small></b></tfoot></strike><bdo id="sibua"></bdo><label id="sibua"></label><nobr id="sibua"><source id="sibua"><menuitem id="sibua"><blockquote id="sibua"></blockquote></menuitem></source></nobr><tbody id="sibua"><u id="sibua"><fieldset id="sibua"></fieldset></u></tbody><nobr id="sibua"></nobr><tr id="sibua"></tr><dd id="sibua"></dd><pre id="sibua"><pre id="sibua"></pre></pre><noframes id="sibua"></noframes><optgroup id="sibua"></optgroup><rp id="sibua"></rp><tt id="sibua"></tt><sup id="sibua"><span id="sibua"><samp id="sibua"></samp></span></sup><em id="sibua"><noframes id="sibua"><p id="sibua"><big id="sibua"></big></p></noframes></em><button id="sibua"><option id="sibua"></option></button><input id="sibua"><object id="sibua"><td id="sibua"><center id="sibua"></center></td></object></input><object id="sibua"></object><delect id="sibua"></delect><blockquote id="sibua"><th id="sibua"><object id="sibua"><s id="sibua"></s></object></th></blockquote><thead id="sibua"></thead><abbr id="sibua"><legend id="sibua"></legend></abbr><xmp id="sibua"></xmp><ul id="sibua"><var id="sibua"><strong id="sibua"><acronym id="sibua"></acronym></strong></var></ul><cite id="sibua"></cite><sup id="sibua"></sup><center id="sibua"><optgroup id="sibua"><bdo id="sibua"></bdo></optgroup></center><thead id="sibua"></thead><style id="sibua"><i id="sibua"><tr id="sibua"><b id="sibua"></b></tr></i></style><ruby id="sibua"><small id="sibua"></small></ruby><rp id="sibua"><input id="sibua"></input></rp><tr id="sibua"><div id="sibua"><button id="sibua"></button></div></tr><dfn id="sibua"></dfn><label id="sibua"></label><address id="sibua"><kbd id="sibua"><strong id="sibua"><label id="sibua"></label></strong></kbd></address><label id="sibua"></label><legend id="sibua"></legend><strike id="sibua"></strike><track id="sibua"><s id="sibua"></s></track><output id="sibua"><nav id="sibua"><nobr id="sibua"><source id="sibua"></source></nobr></nav></output><meter id="sibua"></meter><center id="sibua"></center><legend id="sibua"></legend><tt id="sibua"></tt><small id="sibua"><bdo id="sibua"></bdo></small><pre id="sibua"></pre><big id="sibua"></big><ol id="sibua"><form id="sibua"><blockquote id="sibua"></blockquote></form></ol><label id="sibua"></label><ins id="sibua"><track id="sibua"></track></ins><tr id="sibua"></tr><xmp id="sibua"></xmp><label id="sibua"><th id="sibua"><p id="sibua"></p></th></label><tbody id="sibua"></tbody><small id="sibua"></small><legend id="sibua"><div id="sibua"><big id="sibua"></big></div></legend><track id="sibua"><abbr id="sibua"></abbr></track><dfn id="sibua"></dfn><sup id="sibua"><span id="sibua"><samp id="sibua"></samp></span></sup><meter id="sibua"></meter><blockquote id="sibua"></blockquote><input id="sibua"><object id="sibua"><big id="sibua"><option id="sibua"></option></big></object></input><strong id="sibua"></strong><delect id="sibua"></delect><sup id="sibua"><form id="sibua"><cite id="sibua"><style id="sibua"></style></cite></form></sup><pre id="sibua"></pre><tt id="sibua"></tt><td id="sibua"></td><th id="sibua"></th><dd id="sibua"></dd><tt id="sibua"></tt><acronym id="sibua"></acronym><p id="sibua"><big id="sibua"></big></p><rp id="sibua"></rp><track id="sibua"><s id="sibua"></s></track><input id="sibua"></input><ruby id="sibua"><nobr id="sibua"></nobr></ruby><thead id="sibua"></thead><th id="sibua"></th><div id="sibua"></div><strong id="sibua"><dl id="sibua"><font id="sibua"></font></dl></strong><thead id="sibua"><sup id="sibua"></sup></thead><strong id="sibua"></strong><pre id="sibua"></pre><optgroup id="sibua"><legend id="sibua"><dfn id="sibua"></dfn></legend></optgroup><blockquote id="sibua"></blockquote><em id="sibua"></em><center id="sibua"><output id="sibua"></output></center><sup id="sibua"><form id="sibua"><pre id="sibua"><style id="sibua"></style></pre></form></sup><legend id="sibua"></legend><pre id="sibua"></pre><dfn id="sibua"><acronym id="sibua"><ins id="sibua"></ins></acronym></dfn><pre id="sibua"><label id="sibua"><legend id="sibua"><p id="sibua"></p></legend></label></pre><pre id="sibua"><strike id="sibua"><kbd id="sibua"></kbd></strike></pre><code id="sibua"><legend id="sibua"><p id="sibua"></p></legend></code><style id="sibua"></style><cite id="sibua"></cite><rt id="sibua"><dd id="sibua"><xmp id="sibua"></xmp></dd></rt><tr id="sibua"></tr><ruby id="sibua"><rp id="sibua"><nav id="sibua"><div id="sibua"></div></nav></rp></ruby><nav id="sibua"></nav><b id="sibua"><small id="sibua"><strong id="sibua"></strong></small></b><sup id="sibua"><center id="sibua"><em id="sibua"><noframes id="sibua"></noframes></em></center></sup><dd id="sibua"></dd><span id="sibua"></span><source id="sibua"></source><sup id="sibua"></sup><tfoot id="sibua"></tfoot><sub id="sibua"><tr id="sibua"><abbr id="sibua"></abbr></tr></sub><tbody id="sibua"></tbody><li id="sibua"><small id="sibua"><strong id="sibua"></strong></small></li><bdo id="sibua"></bdo><dfn id="sibua"></dfn><style id="sibua"><thead id="sibua"><tt id="sibua"></tt></thead></style><menu id="sibua"></menu><tbody id="sibua"></tbody><tfoot id="sibua"></tfoot><menuitem id="sibua"></menuitem><bdo id="sibua"></bdo><abbr id="sibua"><b id="sibua"><label id="sibua"><pre id="sibua"></pre></label></b></abbr><progress id="sibua"><em id="sibua"><ruby id="sibua"></ruby></em></progress><option id="sibua"></option><small id="sibua"><bdo id="sibua"><acronym id="sibua"><del id="sibua"></del></acronym></bdo></small><input id="sibua"></input><strong id="sibua"></strong><mark id="sibua"><video id="sibua"><menu id="sibua"></menu></video></mark><center id="sibua"><optgroup id="sibua"></optgroup></center><nav id="sibua"></nav><ins id="sibua"></ins><acronym id="sibua"></acronym><dl id="sibua"><legend id="sibua"></legend></dl><tt id="sibua"></tt><abbr id="sibua"></abbr><label id="sibua"><center id="sibua"></center></label><th id="sibua"></th><label id="sibua"><style id="sibua"></style></label><samp id="sibua"><nobr id="sibua"><listing id="sibua"></listing></nobr></samp><listing id="sibua"><sup id="sibua"><dd id="sibua"></dd></sup></listing><del id="sibua"></del><noframes id="sibua"><span id="sibua"></span></noframes><big id="sibua"><ins id="sibua"><pre id="sibua"></pre></ins></big><dl id="sibua"><th id="sibua"></th></dl><strong id="sibua"><address id="sibua"></address></strong><em id="sibua"><video id="sibua"><menu id="sibua"></menu></video></em><xmp id="sibua"><blockquote id="sibua"></blockquote></xmp><b id="sibua"><small id="sibua"><strong id="sibua"><span id="sibua"></span></strong></small></b></div>
    
    </html>