<li id="mtbmt"></li><abbr id="mtbmt"><listing id="mtbmt"></listing></abbr>

  • <label id="mtbmt"></label><em id="mtbmt"><button id="mtbmt"></button></em>

      1. <dfn id="mtbmt"></dfn>
      2. \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

        此時(shí),我們?nèi)匀粨碛邢嗤捻?yè)面,但我們通過(guò)分離上下文塊來(lái)降低了它的複雜性。 <\/p>\n

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

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

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

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

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

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

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

        或字母:<\/p>\n

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

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

        \n

        條件語(yǔ)句<\/strong><\/p>\n

        Twig還以if<\/code>、elseif<\/code>、if not<\/code>和else<\/code>標(biāo)籤的形式提供條件語(yǔ)句。就像在任何編程語(yǔ)言中一樣,我們可以使用這些標(biāo)籤來(lái)過(guò)濾模板中的條件。假設(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

        過(guò)濾器<\/strong><\/p>\n

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

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

        date<\/code>過(guò)濾器將日期格式化為給定格式。正如我們?cè)谑纠锌吹降模?\/p>\n

        \n\n    \n        \n        Twig Example<\/title>\n    <\/head>\n    <body>
        <h1><a href="http://www.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>我們以月\/日\(chéng)/年的格式顯示日期。除了<code>date<\/code>過(guò)濾器之外,我們還可以使用修飾符字符串使用<code>date_modify<\/code>過(guò)濾器更改日期。例如,如果我們想向日期添加一天,我們可以使用以下內(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>通過(guò)替換所有佔(zhàn)位符來(lái)格式化給定字符串。例如:<\/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>過(guò)濾器去除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>是最重要的過(guò)濾器之一。它過(guò)濾字符串以安全地插入最終輸出中。默認(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>最後,讓我們來(lái)看看調(diào)試。有時(shí)我們需要訪問(wèn)模板變量的所有信息。為此,Twig具有<code>dump()<\/code>函數(shù)。此函數(shù)默認(rèn)情況下不可用。在創(chuàng)建Twig環(huán)境時(shí),我們必須添加<code>Twig_Extension_Debug<\/code>擴(kuò)展:<\/p>\n<pre class='brush:php;toolbar:false;'><?php\n\/\/ 加載我們的自動(dòng)加載器\nrequire_once __DIR__.'\/vendor\/autoload.php';\n\n\/\/ 指定我們的Twig模板位置\n$loader = new Twig_Loader_Filesystem(__DIR__.'\/templates');\n\n\/\/ 實(shí)例化我們的Twig\n$twig = new Twig_Environment($loader);<\/pre>\n<p>此步驟是必要的,這樣我們才不會(huì)意外地在生產(chǎn)服務(wù)器上洩露調(diào)試信息。配置完成後,我們只需使用<code>dump()<\/code>函數(shù)即可轉(zhuǎn)儲(chǔ)有關(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ǔ)知識(shí)的堅(jiān)實(shí)基礎(chǔ),並立即啟動(dòng)您的項(xiàng)目!如果您想更深入地了解Twig,官方網(wǎng)站提供了您可以查閱的非常好的文檔和參考。您使用模板引擎嗎?您對(duì)Twig有什麼看法?您會(huì)將它與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://www.miracleart.cn/zh-tw/" 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="社群" class="head_nava head_nava-template1">社群</a>
                            <div   class="377j5v51b"   id="dropdown-template1" style="display: none;">
                                <div   id="377j5v51b"   class="languagechoose">
                                    <a href="http://www.miracleart.cn/zh-tw/article.html" title="文章" class="languagechoosea on">文章</a>
                                    <a href="http://www.miracleart.cn/zh-tw/faq/zt" title="合集" class="languagechoosea">合集</a>
                                    <a href="http://www.miracleart.cn/zh-tw/wenda.html" title="問(wèn)答" class="languagechoosea">問(wèn)答</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://www.miracleart.cn/zh-tw/course.html" title="課程" class="languagechoosea on">課程</a>
                                    <a href="http://www.miracleart.cn/zh-tw/dic/" title="程式設(shè)計(jì)字典" class="languagechoosea">程式設(shè)計(jì)字典</a>
                                </div>
                            </div>
                        </div>
        
                        <div   id="377j5v51b"   class="head_navs">
                            <a href="javascript:;" title="工具庫(kù)" class="head_nava head_nava-template1_2">工具庫(kù)</a>
                            <div   class="377j5v51b"   id="dropdown-template1_2" style="display: none;">
                                <div   id="377j5v51b"   class="languagechoose">
                                    <a href="http://www.miracleart.cn/zh-tw/toolset/development-tools" title="開(kāi)發(fā)工具" class="languagechoosea on">開(kāi)發(fā)工具</a>
                                    <a href="http://www.miracleart.cn/zh-tw/toolset/website-source-code" title="網(wǎng)站源碼" class="languagechoosea">網(wǎng)站源碼</a>
                                    <a href="http://www.miracleart.cn/zh-tw/toolset/php-libraries" title="PHP 函式庫(kù)" class="languagechoosea">PHP 函式庫(kù)</a>
                                    <a href="http://www.miracleart.cn/zh-tw/toolset/js-special-effects" title="JS特效" class="languagechoosea on">JS特效</a>
                                    <a href="http://www.miracleart.cn/zh-tw/toolset/website-materials" title="網(wǎng)站素材" class="languagechoosea on">網(wǎng)站素材</a>
                                    <a href="http://www.miracleart.cn/zh-tw/toolset/extension-plug-ins" title="擴(kuò)充插件" class="languagechoosea on">擴(kuò)充插件</a>
                                </div>
                            </div>
                        </div>
        
                        <div   id="377j5v51b"   class="head_navs">
                            <a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/game" title="遊戲下載" class="languagechoosea on">遊戲下載</a>
                                    <a href="http://www.miracleart.cn/zh-tw/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-tw')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value="">
                        <a href="javascript:;" title="搜尋"  onclick="searchs('zh-tw')"><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:setlang('zh-cn');" title="簡(jiǎn)體中文" class="languagechoosea">簡(jiǎn)體中文</a>
                                                        <a href="javascript:setlang('en');" title="English" class="languagechoosea">English</a>
                                                        <a href="javascript:;" title="繁體中文" class="languagechoosea">繁體中文</a>
                                                        <a href="javascript:setlang('ja');" title="日本語(yǔ)" class="languagechoosea">日本語(yǔ)</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://www.miracleart.cn/zh-tw/" title="首頁(yè)"
        							class="phpgenera_Details_mainL1a">首頁(yè)</a>
        						<img src="/static/imghw/top_right.png" alt="" />
        												<a href="http://www.miracleart.cn/zh-tw/be/"
        							class="phpgenera_Details_mainL1a">後端開(kāi)發(fā)</a>
        						<img src="/static/imghw/top_right.png" alt="" />
        												<a href="http://www.miracleart.cn/zh-tw/php-weizijiaocheng.html"
        							class="phpgenera_Details_mainL1a">php教程</a>
        						<img src="/static/imghw/top_right.png" alt="" />
        						<span>樹(shù)枝 - 最受歡迎的獨(dú)立PHP模板引擎</span>
        					</div>
        					
        					<div   id="377j5v51b"   class="Articlelist_txts">
        						<div   id="377j5v51b"   class="Articlelist_txts_info">
        							<h1 class="Articlelist_txts_title">樹(shù)枝 - 最受歡迎的獨(dú)立PHP模板引擎</h1>
        							<div   id="377j5v51b"   class="Articlelist_txts_info_head">
        								<div   id="377j5v51b"   class="author_info">
        									<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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開(kāi)發(fā)的PHP流行模板引擎,它簡(jiǎn)化了PHP代碼,並增加了安全和調(diào)試等功能。 Twig同時(shí)作用於項(xiàng)目的frontend和backend,可以從兩個(gè)角度來(lái)看:模板設(shè)計(jì)師的Twig和開(kāi)發(fā)者的Twig。 Twig使用名為<code>Environment</code>的核心對(duì)象來(lái)存儲(chǔ)配置、擴(kuò)展,並從文件系統(tǒng)或其他位置加載模板。 Twig支持嵌套模板(塊),避免模板中元素重複,並能緩存編譯後的模板以加快後續(xù)請(qǐng)求速度。 Twig支持條件語(yǔ)句、循環(huán)和過(guò)濾器來(lái)控制模板中信息的顯示,並提供調(diào)試功能來(lái)轉(zhuǎn)儲(chǔ)模板變量的所有信息。 </p>
        <p><em>本文由Wern Ancheta同行評(píng)審。感謝所有SitePoint的同行評(píng)審員,使SitePoint的內(nèi)容達(dá)到最佳狀態(tài)!</em></p>
        <hr>
        <p>Twig是PHP的模板引擎。但是,PHP本身不是模板引擎嗎?是的,也不是!儘管PHP最初是作為模板引擎,但它的發(fā)展並非如此,雖然我們?nèi)匀豢梢詫⑵溆米髂0逡?,?qǐng)問(wèn)您更喜歡哪個(gè)版本的“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是一種冗長(zhǎng)的語(yǔ)言,在嘗試輸出HTML內(nèi)容時(shí),這種冗長(zhǎng)性會(huì)被放大?,F(xiàn)代模板系統(tǒng)將消除部分冗長(zhǎng)性,並在其之上增加相當(dāng)多的功能。諸如安全和調(diào)試功能之類(lèi)的特性是現(xiàn)代模板引擎的支柱。今天,我們將重點(diǎ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的開(kāi)發(fā)公司)創(chuàng)建的模板引擎。讓我們來(lái)看看它的主要優(yōu)勢(shì)以及如何在項(xiàng)目中使用它。 </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è)您正在運(yùn)行已設(shè)置PHP並全局安裝Composer的環(huán)境。最好的方法是使用Homestead Improved——它可以讓您在5分鐘內(nèi)在與我們使用的完全相同的機(jī)器上開(kāi)始使用,這樣我們就能在同一頁(yè)面上。如果您想了解有關(guān)PHP環(huán)境的更多信息,我們這裡有一本關(guān)於此的優(yōu)秀付費(fèi)書(shū)籍可供購(gòu)買(mǎi)。 </em></p>
        <p>在我們繼續(xù)之前,我們需要先澄清一些事情。作為模板引擎,Twig同時(shí)作用於項(xiàng)目的frontend和backend。因此,我們可以從兩個(gè)不同的角度來(lái)看待Twig:模板設(shè)計(jì)師的Twig和開(kāi)發(fā)者的Twig。一方面,我們準(zhǔn)備所有需要的數(shù)據(jù);另一方面,我們呈現(xiàn)所有這些數(shù)據(jù)。 </p>
        <p><strong>基本用法</strong></p><p>為了舉例說(shuō)明Twig的基本用法,讓我們創(chuàng)建一個(gè)簡(jiǎn)單的項(xiàng)目。首先,我們需要引導(dǎo)Twig。讓我們創(chuàng)建一個(gè)包含以下內(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>的核心對(duì)象。此類(lèi)的實(shí)例用於存儲(chǔ)配置、擴(kuò)展,並從文件系統(tǒng)或其他位置加載模板。在我們的Twig實(shí)例引導(dǎo)後,我們可以繼續(xù)創(chuàng)建一個(gè)<code>index.php</code>文件,在其中加載一些數(shù)據(jù)並將其傳遞給Twig模板。 </p>
        <pre class='brush:php;toolbar:false;'><p>Hello {{ name }}</p></pre>
        <p>這是一個(gè)簡(jiǎn)單的示例;我們正在創(chuàng)建一個(gè)包含產(chǎn)品的數(shù)組,例如我們的機(jī)械鍵盤(pán),我們可以在模板中使用它。然後,我們使用<code>render()</code>方法,它接受模板名稱(這是我們之前定義的模板文件夾中的一個(gè)文件)以及我們要傳遞給模板的數(shù)據(jù)。為了完成我們的示例,讓我們進(jìn)入我們的<code>/templates</code>文件夾並創(chuàng)建一個(gè)<code>index.html</code>文件。首先,讓我們看看模板本身。 </p>
        <pre class='brush:php;toolbar:false;'>composer require twig/twig</pre>
        <p>在瀏覽器中打開(kāi)<code>index.php</code>(訪問(wèn)localhost或homestead.app,具體取決於您如何設(shè)置主機(jī)和服務(wù)器)現(xiàn)在應(yīng)該會(huì)顯示以下屏幕:</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ì)看看我們的模板代碼。有兩種類(lèi)型的分隔符:<code>{{ ... }}</code>用於打印表達(dá)式或操作的結(jié)果,而<code>{% ... %}</code>用於執(zhí)行諸如條件語(yǔ)句和循環(huán)之類(lèi)的語(yǔ)句。這些分隔符是Twig的主要語(yǔ)言結(jié)構(gòu),Twig使用它們來(lái)“告知”模板它必須呈現(xiàn)Twig元素。 </p>
        <p><strong>(以下內(nèi)容與原文類(lèi)似,但做了部分語(yǔ)句調(diào)整和段落劃分,並保持了圖片位置不變)</strong></p>
        <p><strong>佈局</strong></p>
        <p>為了避免在模板中重複元素(如頁(yè)眉和頁(yè)腳),Twig允許我們將模板嵌套在模板中,這些被稱為塊。為了舉例說(shuō)明這一點(diǎn),讓我們將實(shí)際內(nèi)容與示例中的HTML定義分開(kāi)。讓我們創(chuàng)建一個(gè)新的HTML文件並將其命名為<code>layout.html</code>:</p>
        <pre class='brush:php;toolbar:false;'><?php
        // 加載我們的自動(dòng)加載器
        require_once __DIR__.'/vendor/autoload.php';
        
        // 指定我們的Twig模板位置
        $loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
        
        // 實(shí)例化我們的Twig
        $twig = new Twig_Environment($loader);</pre>
        <p>我們創(chuàng)建了一個(gè)名為<code>content</code>的塊。我們的意思是,每個(gè)從<code>layout.html</code>擴(kuò)展的模板都可以實(shí)現(xiàn)一個(gè)<code>content</code>塊,該塊將顯示在該位置。這樣,我們可以多次重用佈局而無(wú)需重寫(xiě)它。在本例中,<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還允許我們只渲染單個(gè)塊。為此,我們需要首先加載模板,然後渲染塊。 </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>此時(shí),我們?nèi)匀粨碛邢嗤捻?yè)面,但我們通過(guò)分離上下文塊來(lái)降低了它的複雜性。 </p>
        <p><strong>緩存</strong></p><p><code>Environment</code>對(duì)像不僅可以用於加載模板。如果我們使用關(guān)聯(lián)目錄的<code>cache</code>選項(xiàng)傳遞,Twig將緩存編譯後的模板,從而避免在後續(xù)請(qǐng)求中解析模板。編譯後的模板將存儲(chǔ)在我們提供的目錄中。請(qǐng)注意,這是編譯模板的緩存,而不是已評(píng)估的模板的緩存。這意味著Twig將解析、編譯並保存模板文件。所有後續(xù)請(qǐng)求仍然需要評(píng)估模板,但第一步已經(jīng)為您完成。讓我們通過(guò)編輯<code>bootstrap.php</code>文件來(lái)緩存示例中的模板:</p>
        <pre class='brush:php;toolbar:false;'><?php echo "<p> Hello " . $name . "</p>"; ?></pre>
        <p><strong>(以下內(nèi)容與原文類(lèi)似,但做了部分語(yǔ)句調(diào)整和段落劃分,並保持了圖片位置不變)</strong></p>
        <p><strong>循環(huán)</strong></p>
        <p>在我們的示例中,我們已經(jīng)看到瞭如何使用Twig進(jìn)行循環(huán)?;旧?,我們使用<code>for</code>標(biāo)籤並為指定數(shù)組中的每個(gè)元素分配一個(gè)別名。在本例中,我們?yōu)?code>products</code>數(shù)組分配了別名<code>product</code>。之後,我們可以使用<code>.</code>運(yùn)算符訪問(wèn)每個(gè)數(shù)組元素中的所有屬性。我們使用<code>endfor</code>標(biāo)籤來(lái)指示循環(huán)的結(jié)束。我們還可以使用<code>..</code>運(yùn)算符循環(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>此運(yùn)算符只是<code>range</code>函數(shù)的語(yǔ)法糖,其工作方式與本機(jī)PHP<code>range</code>函數(shù)相同。同樣有用的選項(xiàng)是向循環(huán)添加條件。使用條件,我們可以過(guò)濾要迭代的元素。假設(shè)我們想要迭代所有值小於250的產(chǎn)品:</p>
        <pre class='brush:php;toolbar:false;'><?php
        // 加載我們的自動(dòng)加載器
        require_once __DIR__.'/vendor/autoload.php';
        
        // 指定我們的Twig模板位置
        $loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
        
        // 實(shí)例化我們的Twig
        $twig = new Twig_Environment($loader);</pre>
        <p><strong>條件語(yǔ)句</strong></p>
        <p>Twig還以<code>if</code>、<code>elseif</code>、<code>if not</code>和<code>else</code>標(biāo)籤的形式提供條件語(yǔ)句。就像在任何編程語(yǔ)言中一樣,我們可以使用這些標(biāo)籤來(lái)過(guò)濾模板中的條件。假設(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>過(guò)濾器</strong></p>
        <p>過(guò)濾器允許我們過(guò)濾傳遞給模板的信息以及顯示信息的格式。讓我們看看一些最常用和最重要的過(guò)濾器。 Twig過(guò)濾器的完整列表可以在這裡找到。 </p>
        <h3 id="日期和-code-date-modify-code">日期和<code>date_modify</code></h3>
        <p><code>date</code>過(guò)濾器將日期格式化為給定格式。正如我們?cè)谑纠锌吹降模?/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>過(guò)濾器之外,我們還可以使用修飾符字符串使用<code>date_modify</code>過(guò)濾器更改日期。例如,如果我們想向日期添加一天,我們可以使用以下內(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>通過(guò)替換所有佔(zhàn)位符來(lái)格式化給定字符串。例如:</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>過(guò)濾器去除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>是最重要的過(guò)濾器之一。它過(guò)濾字符串以安全地插入最終輸出中。默認(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>最後,讓我們來(lái)看看調(diào)試。有時(shí)我們需要訪問(wèn)模板變量的所有信息。為此,Twig具有<code>dump()</code>函數(shù)。此函數(shù)默認(rèn)情況下不可用。在創(chuàng)建Twig環(huán)境時(shí),我們必須添加<code>Twig_Extension_Debug</code>擴(kuò)展:</p>
        <pre class='brush:php;toolbar:false;'><?php
        // 加載我們的自動(dòng)加載器
        require_once __DIR__.'/vendor/autoload.php';
        
        // 指定我們的Twig模板位置
        $loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
        
        // 實(shí)例化我們的Twig
        $twig = new Twig_Environment($loader);</pre>
        <p>此步驟是必要的,這樣我們才不會(huì)意外地在生產(chǎn)服務(wù)器上洩露調(diào)試信息。配置完成後,我們只需使用<code>dump()</code>函數(shù)即可轉(zhuǎn)儲(chǔ)有關(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ǔ)知識(shí)的堅(jiān)實(shí)基礎(chǔ),並立即啟動(dòng)您的項(xiàng)目!如果您想更深入地了解Twig,官方網(wǎng)站提供了您可以查閱的非常好的文檔和參考。您使用模板引擎嗎?您對(duì)Twig有什麼看法?您會(huì)將它與Blade或Smarty等流行的替代方案進(jìn)行比較嗎? </p>
        <p><strong>(以下內(nèi)容為FAQ,原文已包含,此處略去)</strong></p><p>以上是樹(shù)枝 - 最受歡迎的獨(dú)立PHP模板引擎的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!</p>
        
        
        						</div>
        					</div>
        					<div   id="377j5v51b"   class="wzconShengming_sp">
        						<div   id="377j5v51b"   class="bzsmdiv_sp">本網(wǎng)站聲明</div>
        						<div>本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)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>熱門(mén)文章</h2>
        							</div>
        							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/faq/1796821119.html" title="指南:恆星刀片保存文件位置/保存文件丟失/不保存" class="phpgenera_Details_mainR4_bottom_title">指南:恆星刀片保存文件位置/保存文件丟失/不保存</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://www.miracleart.cn/zh-tw/faq/1796827210.html" title="Oguri Cap Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Oguri Cap Build Guide |漂亮的德比志</a>
        									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
        										<span>2 週前</span>
        										<span>By Jack chen</span>
        									</div>
        								</div>
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/faq/1796828723.html" title="Agnes Tachyon Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Agnes Tachyon Build Guide |漂亮的德比志</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://www.miracleart.cn/zh-tw/faq/1796821436.html" title="沙丘:覺(jué)醒 - 高級(jí)行星學(xué)家Quest演練" class="phpgenera_Details_mainR4_bottom_title">沙丘:覺(jué)醒 - 高級(jí)行星學(xué)家Quest演練</a>
        									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
        										<span>3 週前</span>
        										<span>By Jack chen</span>
        									</div>
        								</div>
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/faq/1796821278.html" title="約會(huì)一切:德克和哈珀關(guān)係指南" class="phpgenera_Details_mainR4_bottom_title">約會(huì)一切:德克和哈珀關(guān)係指南</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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title">
        													<h3>Undress AI Tool</h3>
        												</a>
        												<p>免費(fèi)脫衣圖片</p>
        											</div>
        										</div>
        																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
        											<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title">
        													<h3>Undresser.AI Undress</h3>
        												</a>
        												<p>人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片</p>
        											</div>
        										</div>
        																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
        											<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title">
        													<h3>Clothoff.io</h3>
        												</a>
        												<p>AI脫衣器</p>
        											</div>
        										</div>
        																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
        											<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title">
        													<h3>Video Face Swap</h3>
        												</a>
        												<p>使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!</p>
        											</div>
        										</div>
        																</div>
        								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
        									<a href="http://www.miracleart.cn/zh-tw/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>熱門(mén)文章</h2>
        							</div>
        							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/faq/1796821119.html" title="指南:恆星刀片保存文件位置/保存文件丟失/不保存" class="phpgenera_Details_mainR4_bottom_title">指南:恆星刀片保存文件位置/保存文件丟失/不保存</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://www.miracleart.cn/zh-tw/faq/1796827210.html" title="Oguri Cap Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Oguri Cap Build Guide |漂亮的德比志</a>
        									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
        										<span>2 週前</span>
        										<span>By Jack chen</span>
        									</div>
        								</div>
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/faq/1796828723.html" title="Agnes Tachyon Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Agnes Tachyon Build Guide |漂亮的德比志</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://www.miracleart.cn/zh-tw/faq/1796821436.html" title="沙丘:覺(jué)醒 - 高級(jí)行星學(xué)家Quest演練" class="phpgenera_Details_mainR4_bottom_title">沙丘:覺(jué)醒 - 高級(jí)行星學(xué)家Quest演練</a>
        									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
        										<span>3 週前</span>
        										<span>By Jack chen</span>
        									</div>
        								</div>
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/faq/1796821278.html" title="約會(huì)一切:德克和哈珀關(guān)係指南" class="phpgenera_Details_mainR4_bottom_title">約會(huì)一切:德克和哈珀關(guān)係指南</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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_title">
        													<h3>記事本++7.3.1</h3>
        												</a>
        												<p>好用且免費(fèi)的程式碼編輯器</p>
        											</div>
        										</div>
        																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
        											<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_title">
        													<h3>禪工作室 13.0.1</h3>
        												</a>
        												<p>強(qiáng)大的PHP整合開(kāi)發(fā)環(huán)境</p>
        											</div>
        										</div>
        																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
        											<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title">
        													<h3>Dreamweaver CS6</h3>
        												</a>
        												<p>視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具</p>
        											</div>
        										</div>
        																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
        											<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_title">
        													<h3>SublimeText3 Mac版</h3>
        												</a>
        												<p>神級(jí)程式碼編輯軟體(SublimeText3)</p>
        											</div>
        										</div>
        																	</div>
        								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
        									<a href="http://www.miracleart.cn/zh-tw/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>熱門(mén)話題</h2>
        							</div>
        							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
        															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
        									<a href="http://www.miracleart.cn/zh-tw/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>8636</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://www.miracleart.cn/zh-tw/faq/java-tutorial" title="Java教學(xué)" class="phpgenera_Details_mainR4_bottom_title">Java教學(xué)</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>1783</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://www.miracleart.cn/zh-tw/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>1725</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://www.miracleart.cn/zh-tw/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>1577</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://www.miracleart.cn/zh-tw/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>1441</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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/faq/1796822204.html" title="如何在PHP中實(shí)施身份驗(yàn)證和授權(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中實(shí)施身份驗(yàn)證和授權(quán)?" />
        								</a>
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796822204.html" title="如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)?" class="phphistorical_Version2_mids_title">如何在PHP中實(shí)施身份驗(yàn)證和授權(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://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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中的文件上傳,核心在於驗(yàn)證文件類(lèi)型、重命名文件並限制權(quán)限。 1.使用finfo_file()檢查真實(shí)MIME類(lèi)型,僅允許特定類(lèi)型如image/jpeg;2.用uniqid()生成隨機(jī)文件名,存儲(chǔ)至非Web根目錄;3.通過(guò)php.ini和HTML表單限製文件大小,設(shè)置目錄權(quán)限為0755;4.使用ClamAV掃描惡意軟件,增強(qiáng)安全性。這些步驟有效防止安全漏洞,確保文件上傳過(guò)程安全可靠。</p>
        							</div>
        														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
        								<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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ū)別在於類(lèi)型檢查的嚴(yán)格程度。 ==在比較前會(huì)進(jìn)行類(lèi)型轉(zhuǎn)換,例如5=="5"返回true,而===要求值和類(lèi)型都相同才會(huì)返回true,例如5==="5"返回false。使用場(chǎng)景上,===更安全應(yīng)優(yōu)先使用,==僅在需要類(lèi)型轉(zhuǎn)換時(shí)使用。</p>
        							</div>
        														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
        								<a href="http://www.miracleart.cn/zh-tw/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://www.miracleart.cn/zh-tw/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é)運(yùn)算的方法如下:1.加法用 號(hào),支持整數(shù)和浮點(diǎn)數(shù),也可用於變量,字符串?dāng)?shù)字會(huì)自動(dòng)轉(zhuǎn)換但不推薦依賴;2.減法用-號(hào),變量同理,類(lèi)型轉(zhuǎn)換同樣適用;3.乘法用*號(hào),適用於數(shù)字及類(lèi)似字符串;4.除法用/號(hào),需避免除以零,並註意結(jié)果可能是浮點(diǎn)數(shù);5.取模用%號(hào),可用於判斷奇偶數(shù),處理負(fù)數(shù)時(shí)餘數(shù)符號(hào)與被除數(shù)一致。正確使用這些運(yùn)算符的關(guān)鍵在於確保數(shù)據(jù)類(lèi)型清晰並處理好邊界情況。</p>
        							</div>
        														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796821728.html" title="如何與PHP的NOSQL數(shù)據(jù)庫(kù)(例如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ù)庫(kù)(例如MongoDB,Redis)進(jìn)行交互?" />
        								</a>
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796821728.html" title="如何與PHP的NOSQL數(shù)據(jù)庫(kù)(例如MongoDB,Redis)進(jìn)行交互?" class="phphistorical_Version2_mids_title">如何與PHP的NOSQL數(shù)據(jù)庫(kù)(例如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可以通過(guò)特定擴(kuò)展或庫(kù)與MongoDB和Redis等NoSQL數(shù)據(jù)庫(kù)交互。首先,使用MongoDBPHP驅(qū)動(dòng)(通過(guò)PECL或Composer安裝)創(chuàng)建客戶端實(shí)例並操作數(shù)據(jù)庫(kù)及集合,支持插入、查詢、聚合等操作;其次,使用Predis庫(kù)或phpredis擴(kuò)展連接Redis,執(zhí)行鍵值設(shè)置與獲取,推薦phpredis用於高性能場(chǎng)景,Predis則便於快速部署;兩者均適用於生產(chǎn)環(huán)境且文檔完善。</p>
        							</div>
        														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796823337.html" title="我如何了解最新的PHP開(kāi)發(fā)和最佳實(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/175061139068429.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="我如何了解最新的PHP開(kāi)發(fā)和最佳實(shí)踐?" />
        								</a>
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796823337.html" title="我如何了解最新的PHP開(kāi)發(fā)和最佳實(shí)踐?" class="phphistorical_Version2_mids_title">我如何了解最新的PHP開(kāi)發(fā)和最佳實(shí)踐?</a>
        								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 23, 2025 am	 12:56 AM</span>
        								<p class="Articlelist_txts_p">TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource</p>
        							</div>
        														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796823335.html" title="什麼是PHP,為什麼它用於Web開(kāi)發(fā)?" 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/175061135143093.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="什麼是PHP,為什麼它用於Web開(kāi)發(fā)?" />
        								</a>
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796823335.html" title="什麼是PHP,為什麼它用於Web開(kāi)發(fā)?" class="phphistorical_Version2_mids_title">什麼是PHP,為什麼它用於Web開(kāi)發(fā)?</a>
        								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 23, 2025 am	 12:55 AM</span>
        								<p class="Articlelist_txts_p">PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti</p>
        							</div>
        														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796824143.html" title="如何設(shè)置PHP時(shí)區(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/431/639/175078443031614.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何設(shè)置PHP時(shí)區(qū)?" />
        								</a>
        								<a href="http://www.miracleart.cn/zh-tw/faq/1796824143.html" title="如何設(shè)置PHP時(shí)區(qū)?" class="phphistorical_Version2_mids_title">如何設(shè)置PHP時(shí)區(qū)?</a>
        								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 25, 2025 am	 01:00 AM</span>
        								<p class="Articlelist_txts_p">tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()</p>
        							</div>
        													</div>
        
        													<a href="http://www.miracleart.cn/zh-tw/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í)者快速成長(zhǎng)!</p>
                </div>
                <div   id="377j5v51b"   class="footermid">
                    <a href="http://www.miracleart.cn/zh-tw/about/us.html">關(guān)於我們</a>
                    <a href="http://www.miracleart.cn/zh-tw/about/disclaimer.html">免責(zé)聲明</a>
                    <a href="http://www.miracleart.cn/zh-tw/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://www.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="zrbsc" class="pl_css_ganrao" style="display: none;"><big id="zrbsc"><xmp id="zrbsc"></xmp></big><source id="zrbsc"><dl id="zrbsc"><button id="zrbsc"></button></dl></source><table id="zrbsc"></table><code id="zrbsc"></code><sup id="zrbsc"></sup><div id="zrbsc"></div><optgroup id="zrbsc"><small id="zrbsc"></small></optgroup><fieldset id="zrbsc"></fieldset><s id="zrbsc"><rt id="zrbsc"></rt></s><u id="zrbsc"><th id="zrbsc"><optgroup id="zrbsc"></optgroup></th></u><dd id="zrbsc"></dd><dl id="zrbsc"><legend id="zrbsc"><rt id="zrbsc"><dd id="zrbsc"></dd></rt></legend></dl><wbr id="zrbsc"></wbr><dfn id="zrbsc"><abbr id="zrbsc"></abbr></dfn><sub id="zrbsc"><center id="zrbsc"><acronym id="zrbsc"><ruby id="zrbsc"></ruby></acronym></center></sub><style id="zrbsc"><bdo id="zrbsc"><code id="zrbsc"><legend id="zrbsc"></legend></code></bdo></style><s id="zrbsc"><rt id="zrbsc"></rt></s><listing id="zrbsc"></listing><abbr id="zrbsc"><b id="zrbsc"><optgroup id="zrbsc"></optgroup></b></abbr><tr id="zrbsc"></tr><menuitem id="zrbsc"></menuitem><em id="zrbsc"><listing id="zrbsc"><dfn id="zrbsc"><ol id="zrbsc"></ol></dfn></listing></em><xmp id="zrbsc"><p id="zrbsc"><big id="zrbsc"></big></p></xmp><pre id="zrbsc"></pre><th id="zrbsc"><div id="zrbsc"></div></th><track id="zrbsc"><th id="zrbsc"></th></track><th id="zrbsc"></th><center id="zrbsc"><dd id="zrbsc"><font id="zrbsc"><pre id="zrbsc"></pre></font></dd></center><big id="zrbsc"><strong id="zrbsc"><strike id="zrbsc"></strike></strong></big><sup id="zrbsc"><dl id="zrbsc"></dl></sup><ul id="zrbsc"></ul><li id="zrbsc"><mark id="zrbsc"><video id="zrbsc"><dfn id="zrbsc"></dfn></video></mark></li><ul id="zrbsc"></ul><table id="zrbsc"></table><cite id="zrbsc"><fieldset id="zrbsc"><rt id="zrbsc"></rt></fieldset></cite><thead id="zrbsc"><acronym id="zrbsc"></acronym></thead><big id="zrbsc"></big><fieldset id="zrbsc"><thead id="zrbsc"><source id="zrbsc"><pre id="zrbsc"></pre></source></thead></fieldset><strong id="zrbsc"></strong><var id="zrbsc"><table id="zrbsc"><delect id="zrbsc"></delect></table></var><option id="zrbsc"></option><em id="zrbsc"><tt id="zrbsc"><option id="zrbsc"><em id="zrbsc"></em></option></tt></em><i id="zrbsc"></i><em id="zrbsc"></em><button id="zrbsc"></button><code id="zrbsc"></code><option id="zrbsc"></option><em id="zrbsc"></em><acronym id="zrbsc"><strike id="zrbsc"></strike></acronym><blockquote id="zrbsc"></blockquote><rt id="zrbsc"></rt><rp id="zrbsc"></rp><del id="zrbsc"></del><fieldset id="zrbsc"></fieldset><wbr id="zrbsc"><acronym id="zrbsc"></acronym></wbr><s id="zrbsc"></s><dd id="zrbsc"><pre id="zrbsc"><dfn id="zrbsc"></dfn></pre></dd><bdo id="zrbsc"></bdo><noframes id="zrbsc"><abbr id="zrbsc"></abbr></noframes><samp id="zrbsc"><address id="zrbsc"><sup id="zrbsc"></sup></address></samp><dfn id="zrbsc"><abbr id="zrbsc"></abbr></dfn><big id="zrbsc"></big><ruby id="zrbsc"></ruby><th id="zrbsc"></th><dfn id="zrbsc"><blockquote id="zrbsc"></blockquote></dfn><thead id="zrbsc"></thead><b id="zrbsc"><em id="zrbsc"><listing id="zrbsc"><li id="zrbsc"></li></listing></em></b><var id="zrbsc"></var><big id="zrbsc"><xmp id="zrbsc"></xmp></big><strike id="zrbsc"><wbr id="zrbsc"><blockquote id="zrbsc"></blockquote></wbr></strike><bdo id="zrbsc"></bdo><dfn id="zrbsc"><abbr id="zrbsc"></abbr></dfn><strong id="zrbsc"><abbr id="zrbsc"></abbr></strong><tt id="zrbsc"></tt><video id="zrbsc"><li id="zrbsc"></li></video><dfn id="zrbsc"></dfn><pre id="zrbsc"></pre><pre id="zrbsc"></pre><object id="zrbsc"></object><input id="zrbsc"><object id="zrbsc"></object></input><sup id="zrbsc"><source id="zrbsc"><th id="zrbsc"><strike id="zrbsc"></strike></th></source></sup><em id="zrbsc"><output id="zrbsc"><option id="zrbsc"></option></output></em><span id="zrbsc"></span><acronym id="zrbsc"></acronym><button id="zrbsc"></button><kbd id="zrbsc"><dfn id="zrbsc"><button id="zrbsc"><table id="zrbsc"></table></button></dfn></kbd><em id="zrbsc"><sup id="zrbsc"><ruby id="zrbsc"></ruby></sup></em><p id="zrbsc"><s id="zrbsc"><dl id="zrbsc"><tbody id="zrbsc"></tbody></dl></s></p><ol id="zrbsc"></ol><track id="zrbsc"><small id="zrbsc"><bdo id="zrbsc"><i id="zrbsc"></i></bdo></small></track><i id="zrbsc"></i><form id="zrbsc"></form><strong id="zrbsc"><menu id="zrbsc"><input id="zrbsc"><dl id="zrbsc"></dl></input></menu></strong><label id="zrbsc"><listing id="zrbsc"><dfn id="zrbsc"></dfn></listing></label><wbr id="zrbsc"></wbr><em id="zrbsc"><mark id="zrbsc"><ins id="zrbsc"></ins></mark></em><u id="zrbsc"></u><pre id="zrbsc"></pre><source id="zrbsc"></source><optgroup id="zrbsc"></optgroup></div>
        
        </html>