Home Backend Development PHP Tutorial Reading and writing XML files with PHP_PHP tutorial

Reading and writing XML files with PHP_PHP tutorial

Jul 13, 2016 pm 05:48 PM
domdocument php xml main Can and document generate of Read and write read pass

PHP can easily generate and read XML files. PHP mainly completes XML reading and writing operations through DOMDocument, DOMElement and DOMNodeList. Below is a brief explanation of how to use these classes.

1. Generate XML file
For an XML file as follows.

[html]


PHP Access MySql Database Basics
http://blog.csdn.net/morewindows/article/details/7102362



PHP Access MySql Database Basics
http://blog.csdn.net/morewindows/article/details/7102362

Let’s see how to generate it using PHP:

First create a new DOMDocument object and set the encoding format.

$dom = newDOMDocument('1.0', 'UTF-8');

$dom->formatOutput= true;

Create the

node and the node</p> <p>$rootelement =$dom->createElement("article");</p> <p>$title =$dom->createElement("title", "PHP Access MySql Database - Elementary");</p> <p> </p> <p>Then create a <link> node with text content</p> <p>$link =$dom->createElement("link","http://blog.csdn.net/morewindows/article/details/7102362");</p> <p>You can also generate a <link> node first and then add text content to it. </p> <p>$link = $dom->createElement("link");</p> <p>$linktext =$dom->createTextNode('http://blog.csdn.net/morewindows/article/details/7102362');</p> <p>$link->appendChild($linktext);</p> <p> </p> <p>Then add the <title> and <link> nodes to the <article> node </p> <p>$rootelement->appendChild($title);</p> <p>$rootelement->appendChild($link);</p> <p> </p> <p>Finally, add the <article> node to the DOMDocument object, </p> <p>$dom->appendChild($rootelement);</p> <p> </p> <p>A complete XML is now generated. Then regenerate the entire XML, </p> <p>echo $dom->saveXML() ;</p> <p>saveXML() can also input only part of the XML text. For example, echo $dom->saveXML($link); will only output the <link> node: <link>http://blog.csdn. net/morewindows/article/details/7102362</link></p> <p> </p> <p>The following is a complete example of outputting data content to an XML file in PHP. This example will output a PHP array to an XML file. </p> <p>[php] <?php <br /> //Output the array into an XML file <br /> // by MoreWindows( http://blog.csdn.net/MoreWindows ) <br /> $article_array = array( <br /> "First article" => array( <br> "title"=>"Access MySql Database with PHP - Elementary", <br> "link"=>"http://blog.csdn.net/morewindows/article/details/7102362" <br> ), <br> "Part 2" => array( <br> "title"=>"PHP Access MySql Database Intermediate Smarty Technology", <br> "link"=>"http://blog.csdn.net/morewindows/article/details/7094642" <br> ), <br> "Part 3" => array( <br> "title"=>"PHP Access MySql Database Advanced AJAX Technology", <br> "link"=>"http://blog.csdn.net/morewindows/article/details/7086524" <br> ), <br> ); <br> $dom = new DOMDocument('1.0', 'UTF-8'); <br> $dom->formatOutput = true; <br> $rootelement = $dom->createElement("MoreWindows"); <br> foreach ($article_array as $key=>$value) <br> { <br> $article = $dom->createElement("article", $key); <br> $title = $dom->createElement("title", $value['title']); <br> $link = $dom->createElement("link", $value['link']); <br> $article->appendChild($title); <br> $article->appendChild($link); <br> $rootelement->appendChild($article); <br> } <br> $dom->appendChild($rootelement); <br> $filename = "D:\test.xml"; <br> echo 'XML file size' . $dom->save($filename) . 'Bytes'; <br> ?> <br> <?php<br /> //Output the array to an XML file <br /> // by MoreWindows( http://blog.csdn.net/MoreWindows )<br /> $article_array = array(<br /> "First article" => array(<br /> "title"=>"Access MySql database with PHP - Elementary",<br> "link"=>"http://blog.csdn.net/morewindows/article/details/7102362"<br> ),<br> "Part 2" => array(<br> "title"=>"PHP Access MySql Database Intermediate Smarty Technology",<br> "link"=>"http://blog.csdn.net/morewindows/article/details/7094642"<br> ),<br> "Part 3" => array(<br> "title"=>"PHP Access MySql Database Advanced AJAX Technology",<br> "link"=>"http://blog.csdn.net/morewindows/article/details/7086524"<br> ),<br> );<br> $dom = new DOMDocument('1.0', 'UTF-8');<br> $dom->formatOutput = true;<br> $rootelement = $dom->createElement("MoreWindows");<br> foreach ($article_array as $key=>$value)<br> {<br> $article = $dom->createElement("article", $key);<br> $title = $dom->createElement("title", $value['title']);<br> $link = $dom->createElement("link", $value['link']);<br> $article->appendChild($title);<br> $article->appendChild($link);<br> $rootelement->appendChild($article);<br> }<br> $dom->appendChild($rootelement);<br> $filename = "D:\test.xml";<br> echo 'XML file size' . $dom->save($filename) . 'Bytes';<br> ?><br> Running this PHP will generate the test.xml file on the D drive (Win7 + XAMPP + IE9.0 test passed) </p> <p> </p> <p>2. Read XML file <br> Take reading the D:\test.xml generated in the previous article as an example: </p> <p>[php] <?php <br /> //读取XML文件  <br /> // by MoreWindows( http://blog.csdn.net/MoreWindows )  <br /> $filename = "D:\test.xml"; <br /> $article_array = array(); <br />  <br /> $dom = new DOMDocument('1.0', 'UTF-8'); <br /> $dom->load($filename); <br>  <br> //得到<article>结点  <br> $articles = $dom->getElementsByTagName("article"); <br> echo '<article> 结点个数 ' . $articles->length; <br> foreach ($articles as $article) <br> { <br>     $id = $article->getElementsByTagName("id")->item(0)->nodeValue; <br>     $title = $article->getElementsByTagName("title")->item(0)->nodeValue; <br>     $link = $article->getElementsByTagName("link")->item(0)->nodeValue; <br>     $article_array[$id] = array('title'=>$title, 'link'=>$link); <br> } <br>  <br> //输出结果  <br> echo "<pre class="brush:php;toolbar:false">"; <br> var_dump($article_array); <br> echo "</pre>"; <br> ?> <br> <?php<br /> //读取XML文件<br /> // by MoreWindows( http://blog.csdn.net/MoreWindows )<br /> $filename = "D:\test.xml";<br /> $article_array = array();</p> <p>$dom = new DOMDocument('1.0', 'UTF-8');<br /> $dom->load($filename);</p> <p>//得到<article>结点<br> $articles = $dom->getElementsByTagName("article");<br> echo '<article> 结点个数 ' . $articles->length;<br> foreach ($articles as $article)<br> {<br>  $id = $article->getElementsByTagName("id")->item(0)->nodeValue;<br>  $title = $article->getElementsByTagName("title")->item(0)->nodeValue;<br>  $link = $article->getElementsByTagName("link")->item(0)->nodeValue;<br>  $article_array[$id] = array('title'=>$title, 'link'=>$link);<br> }</p> <p>//输出结果<br> echo "<pre class="brush:php;toolbar:false">";<br> var_dump($article_array);<br> echo "</pre>";<br> ?><br> 运行结果如下:</p> <p> <img src="/static/imghw/default1.png" data-src="http://www.bkjia.com/uploads/allimg/131122/144SK461-0.gif" class="lazy" alt=""><br> <br> 摘自 MoreWindows</p> <p align="left"></p> <div style="display:none;"> <span id="url" itemprop="url">http://www.bkjia.com/PHPjc/478414.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/478414.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">PHP可以方便的生成和读取XML文件。PHP主要通过DOMDocument、DOMElement和DOMNodeList来完成XML的读取与写入操作的。下面就简要说明下如何使用这些...</span> </div> <div class="art_confoot"></div> </div> </div> <div class="wzconShengming_sp"> <div class="bzsmdiv_sp">Statement of this Website</div> <div>The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact 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> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div 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> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <!-- <div class="phpgenera_Details_mainR4"> <div class="phpmain1_4R_readrank"> <div 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>Hot Article</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796780570.html" title="R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>2 weeks ago</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796773439.html" title="Repo: How To Revive Teammates" class="phpgenera_Details_mainR4_bottom_title">Repo: How To Revive Teammates</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 weeks ago</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796774171.html" title="Hello Kitty Island Adventure: How To Get Giant Seeds" class="phpgenera_Details_mainR4_bottom_title">Hello Kitty Island Adventure: How To Get Giant Seeds</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796775427.html" title="How Long Does It Take To Beat Split Fiction?" class="phpgenera_Details_mainR4_bottom_title">How Long Does It Take To Beat Split Fiction?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By DDD</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796775336.html" title="R.E.P.O. Save File Location: Where Is It & How to Protect It?" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O. Save File Location: Where Is It & How to Protect It?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By DDD</span> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/article.html">Show More</a> </div> </div> </div> --> <div class="phpgenera_Details_mainR3"> <div class="phpmain1_4R_readrank"> <div 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>Hot AI Tools</h2> </div> <div class="phpgenera_Details_mainR3_bottom"> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/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 class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title"> <h3>Undresser.AI Undress</h3> </a> <p>AI-powered app for creating realistic nude photos</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/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 class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title"> <h3>AI Clothes Remover</h3> </a> <p>Online AI tool for removing clothes from photos.</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/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 class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title"> <h3>Undress AI Tool</h3> </a> <p>Undress images for free</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/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 class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title"> <h3>Clothoff.io</h3> </a> <p>AI clothes remover</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/ai/ai-hentai-generator" title="AI Hentai Generator" 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/173405034393877.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Hentai Generator" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/ai/ai-hentai-generator" title="AI Hentai Generator" class="phpmain_tab2_mids_title"> <h3>AI Hentai Generator</h3> </a> <p>Generate AI Hentai for free.</p> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/ai">Show More</a> </div> </div> </div> <script src="https://sw.php.cn/hezuo/cac1399ab368127f9b113b14eb3316d0.js" type="text/javascript"></script> <div class="phpgenera_Details_mainR4"> <div class="phpmain1_4R_readrank"> <div 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>Hot Article</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796780570.html" title="R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>2 weeks ago</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796773439.html" title="Repo: How To Revive Teammates" class="phpgenera_Details_mainR4_bottom_title">Repo: How To Revive Teammates</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 weeks ago</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796774171.html" title="Hello Kitty Island Adventure: How To Get Giant Seeds" class="phpgenera_Details_mainR4_bottom_title">Hello Kitty Island Adventure: How To Get Giant Seeds</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796775427.html" title="How Long Does It Take To Beat Split Fiction?" class="phpgenera_Details_mainR4_bottom_title">How Long Does It Take To Beat Split Fiction?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By DDD</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/1796775336.html" title="R.E.P.O. Save File Location: Where Is It & How to Protect It?" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O. Save File Location: Where Is It & How to Protect It?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By DDD</span> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/article.html">Show More</a> </div> </div> </div> <div class="phpgenera_Details_mainR3"> <div class="phpmain1_4R_readrank"> <div 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>Hot Tools</h2> </div> <div class="phpgenera_Details_mainR3_bottom"> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/toolset/development-tools/92" title="Notepad++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="Notepad++7.3.1" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/toolset/development-tools/92" title="Notepad++7.3.1" class="phpmain_tab2_mids_title"> <h3>Notepad++7.3.1</h3> </a> <p>Easy-to-use and free code editor</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/toolset/development-tools/93" title="SublimeText3 Chinese version" 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 Chinese version" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/toolset/development-tools/93" title="SublimeText3 Chinese version" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Chinese version</h3> </a> <p>Chinese version, very easy to use</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/toolset/development-tools/121" title="Zend Studio 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="Zend Studio 13.0.1" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/toolset/development-tools/121" title="Zend Studio 13.0.1" class="phpmain_tab2_mids_title"> <h3>Zend Studio 13.0.1</h3> </a> <p>Powerful PHP integrated development environment</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/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 class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title"> <h3>Dreamweaver CS6</h3> </a> <p>Visual web development tools</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/toolset/development-tools/500" title="SublimeText3 Mac version" 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 version" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/toolset/development-tools/500" title="SublimeText3 Mac version" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Mac version</h3> </a> <p>God-level code editing software (SublimeText3)</p> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/ai">Show More</a> </div> </div> </div> <div class="phpgenera_Details_mainR4"> <div class="phpmain1_4R_readrank"> <div 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>Hot Topics</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/gmailyxdlrkzn" title="Where is the login entrance for gmail email?" class="phpgenera_Details_mainR4_bottom_title">Where is the login entrance for gmail email?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>7316</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>9</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/java-tutorial" title="Java Tutorial" class="phpgenera_Details_mainR4_bottom_title">Java Tutorial</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1625</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>14</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/cakephp-tutor" title="CakePHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">CakePHP Tutorial</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1349</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>46</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/laravel-tutori" title="Laravel Tutorial" class="phpgenera_Details_mainR4_bottom_title">Laravel Tutorial</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1261</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>25</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/faq/php-tutorial" title="PHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">PHP Tutorial</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1208</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>29</span> </div> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/faq/zt">Show More</a> </div> </div> </div> </div> </div> <div class="Article_Details_main2"> <div class="phpgenera_Details_mainL4"> <div 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 class="phpgenera_Details_mainL4_info"> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796604977.html" title="CakePHP Project Configuration" 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/202409/10/2024091017250464952.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP Project Configuration" /> </a> <a href="https://www.php.cn/faq/1796604977.html" title="CakePHP Project Configuration" class="phphistorical_Version2_mids_title">CakePHP Project Configuration</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:25 PM</span> <p class="Articlelist_txts_p">In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796733273.html" title="PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian" 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/000/000/080/676a727698393240.png?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian" /> </a> <a href="https://www.php.cn/faq/1796733273.html" title="PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian" class="phphistorical_Version2_mids_title">PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian</a> <span class="Articlelist_txts_time">Dec 24, 2024 pm 04:42 PM</span> <p class="Articlelist_txts_p">PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796604998.html" title="CakePHP Date and Time" 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/000/887/227/172596042710877.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP Date and Time" /> </a> <a href="https://www.php.cn/faq/1796604998.html" title="CakePHP Date and Time" class="phphistorical_Version2_mids_title">CakePHP Date and Time</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:27 PM</span> <p class="Articlelist_txts_p">To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796604999.html" title="CakePHP File upload" 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/000/000/164/172596043255110.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP File upload" /> </a> <a href="https://www.php.cn/faq/1796604999.html" title="CakePHP File upload" class="phphistorical_Version2_mids_title">CakePHP File upload</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:27 PM</span> <p class="Articlelist_txts_p">To work on file upload we are going to use the form helper. Here, is an example for file upload.</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796604978.html" title="CakePHP Routing" 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/000/465/014/172596030742788.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP Routing" /> </a> <a href="https://www.php.cn/faq/1796604978.html" title="CakePHP Routing" class="phphistorical_Version2_mids_title">CakePHP Routing</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:25 PM</span> <p class="Articlelist_txts_p">In this chapter, we are going to learn the following topics related to routing ?</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796605002.html" title="Discuss CakePHP" 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/202409/10/2024091017281739989.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Discuss CakePHP" /> </a> <a href="https://www.php.cn/faq/1796605002.html" title="Discuss CakePHP" class="phphistorical_Version2_mids_title">Discuss CakePHP</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:28 PM</span> <p class="Articlelist_txts_p">CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796728164.html" title="How To Set Up Visual Studio Code (VS Code) for PHP Development" 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/000/000/080/6764e39e44ffe544.png?x-oss-process=image/resize,m_fill,h_207,w_330" alt="How To Set Up Visual Studio Code (VS Code) for PHP Development" /> </a> <a href="https://www.php.cn/faq/1796728164.html" title="How To Set Up Visual Studio Code (VS Code) for PHP Development" class="phphistorical_Version2_mids_title">How To Set Up Visual Studio Code (VS Code) for PHP Development</a> <span class="Articlelist_txts_time">Dec 20, 2024 am 11:31 AM</span> <p class="Articlelist_txts_p">Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/faq/1796604997.html" title="CakePHP Creating Validators" 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/000/000/164/172596041825531.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP Creating Validators" /> </a> <a href="https://www.php.cn/faq/1796604997.html" title="CakePHP Creating Validators" class="phphistorical_Version2_mids_title">CakePHP Creating Validators</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:26 PM</span> <p class="Articlelist_txts_p">Validator can be created by adding the following two lines in the controller.</p> </div> </div> <a href="https://www.php.cn/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 class="footer"> <div class="footertop"> <img src="/static/imghw/logo.png" alt=""> <p>Public welfare online PHP training,Help PHP learners grow quickly!</p> </div> <div class="footermid"> <a href="https://www.php.cn/about/us.html">About us</a> <a href="https://www.php.cn/about/disclaimer.html">Disclaimer</a> <a href="https://www.php.cn/update/article_0_1.html">Sitemap</a> </div> <div class="footerbottom"> <p> © php.cn All rights reserved </p> </div> </div> </footer> <input type="hidden" id="verifycode" value="/captcha.html"> <script>layui.use(['element', 'carousel'], function () {var element = layui.element;$ = layui.jquery;var carousel = layui.carousel;carousel.render({elem: '#test1', width: '100%', height: '330px', arrow: 'always'});$.getScript('/static/js/jquery.lazyload.min.js', function () {$("img").lazyload({placeholder: "/static/images/load.jpg", effect: "fadeIn", threshold: 200, skip_invisible: false});});});</script> <script src="/static/js/common_new.js"></script> <script type="text/javascript" src="/static/js/jquery.cookie.js?1743505606"></script> <script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script> <link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css?2' type='text/css' media='all' /> <script type='text/javascript' src='/static/js/viewer.min.js?1'></script> <script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script> <script type="text/javascript" src="/static/js/global.min.js?5.5.53"></script> <script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function () { var u = "https://tongji.php.cn/"; _paq.push(['setTrackerUrl', u + 'matomo.php']); _paq.push(['setSiteId', '9']); var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s); })(); </script> <script> // top layui.use(function () { var util = layui.util; util.fixbar({ on: { mouseenter: function (type) { layer.tips(type, this, { tips: 4, fixed: true, }); }, mouseleave: function (type) { layer.closeAll("tips"); }, }, }); }); document.addEventListener("DOMContentLoaded", (event) => { // 定义一个函数来处理滚动链接的点击事件 function setupScrollLink(scrollLinkId, targetElementId) { const scrollLink = document.getElementById(scrollLinkId); const targetElement = document.getElementById(targetElementId); if (scrollLink && targetElement) { scrollLink.addEventListener("click", (e) => { e.preventDefault(); // 阻止默认链接行为 targetElement.scrollIntoView({ behavior: "smooth" }); // 平滑滚动到目标元素 }); } else { console.warn( `Either scroll link with ID '${scrollLinkId}' or target element with ID '${targetElementId}' not found.` ); } } // 使用该函数设置多个滚动链接 setupScrollLink("Article_Details_main1L2s_1", "article_main_title1"); setupScrollLink("Article_Details_main1L2s_2", "article_main_title2"); setupScrollLink("Article_Details_main1L2s_3", "article_main_title3"); setupScrollLink("Article_Details_main1L2s_4", "article_main_title4"); setupScrollLink("Article_Details_main1L2s_5", "article_main_title5"); setupScrollLink("Article_Details_main1L2s_6", "article_main_title6"); // 可以继续添加更多的滚动链接设置 }); window.addEventListener("scroll", function () { var fixedElement = document.getElementById("Article_Details_main1Lmain"); var scrollTop = window.scrollY || document.documentElement.scrollTop; // 兼容不同浏览器 var clientHeight = window.innerHeight || document.documentElement.clientHeight; // 视口高度 var scrollHeight = document.documentElement.scrollHeight; // 页面总高度 // 计算距离底部的距离 var distanceToBottom = scrollHeight - scrollTop - clientHeight; // 当距离底部小于或等于300px时,取消固定定位 if (distanceToBottom <= 980) { fixedElement.classList.remove("Article_Details_main1Lmain"); fixedElement.classList.add("Article_Details_main1Lmain_relative"); } else { // 否则,保持固定定位 fixedElement.classList.remove("Article_Details_main1Lmain_relative"); fixedElement.classList.add("Article_Details_main1Lmain"); } }); </script> </body> </html>