首页 php教程 php手册 PHP实现采集抓取淘宝网单个商品信息

PHP实现采集抓取淘宝网单个商品信息

Jun 06, 2016 pm 08:14 PM
php 抓取 采集

这篇文章主要介绍了PHP实现采集抓取淘宝网单个商品信息,本文是一种实现思路,使用file_get_contents函数实现,并给出了采集正则,需要的朋友可以参考下

调用淘宝的数据可以使用淘宝提供的api,如果只需调用淘宝商品图片名称等公开信息在自己网站上,使用php中的 file_get_contents 函数实现即可。

思路:

file_get_contents(url) 该函数根据 url 如 将该网页内容(源码)以字符串形式输出(一个整字符串),然后配合preg_match,preg_replace等这些正则表达式操作就可以实现获取该url特定div,img等信息了。当然前题是淘宝在单个商品页面的结构是固定的,如500图的img中id就是J_ImgBooth!

具体实现方法:(获取500图,名称,价格,属性及商品描述)

复制代码 代码如下:


$text=file_get_contents("http://item.taobao.com/item.htm?id=2380347279"); //将url地址上页面内容保存进$text

A.获取500图:

复制代码 代码如下:


preg_match('/]*id="J_ImgBooth"[^r]*rc=\"([^"]*)\"[^>]*>/', $text, $img);
//运用正则抓取img标签中id为J_ImgBooth的img,$img[0]为该500图img标签,$img[1]为500图的图片地址;

B. 获取名称:

复制代码 代码如下:


preg_match('/([^<>]*)<\/title>/', $text, $title); <br> //因为正文中的商品名称标签没有特殊class或id正则不好抓取,就抓<title>标签中的内容了,一般来说title中内容就是商品名称了(实际有些出入),$title[0]整个title标签 $title[1]标签中内容;<br> $title=iconv('GBK','UTF-8',$title);<br> //如果你的网站是utf8编码,那么需要进行一下转码(淘宝是gbk编码)<br> </p> <p>C.获取价格:</p> <p></p> <p><span>复制代码</span> 代码如下:</p> <p><br> preg_match('/<([a-z]+)[^i]*id=\"J_StrPrice\"[^>]*>([^<]*)<\/\\1>/is', $text, $price);<br> //同理获取id为J_StrPrice的标签内容$price[2], $price[0]是整个标签, $price[1]为strong标签名;<br> $price=floatval($price);//放入数据库估计还有转一下变量类型<br> </p> <p>D.获取属性:</p> <p>这之前获取的内容都是在单标签中相对只需一个正则就可搞定,然而如果要获取如</p> <p></p> <p><span>复制代码</span> 代码如下:</p> <p><br> …<br>  <br> <div id=”xxx”><br>  <br> …<br>  <br> <ul><br>  <br> …<br>  <br> </ul><br>  <br> <div>…<br>  <br> <div>…<br>  <br> </div><br>  <br> </div><br>  <br> </div><br>  <br> …<br> </p> <p>这样特定div中有未知n个<>标签,获取该特定div将会非常的困难,搜了下网上,最接近的也只是”/<([a-z]+)[^>]*>([^<>]|(?R))*<\/\\1>/”这样使用递归抓取标签对,但是他不能抓特定标签,所以想要轻松抓取class=”attributes”的div我是没法办到了。但是淘宝网页有其特殊性,就是它的各个标签结构基本是固定的…<div>…</div>标签后面不是</div><div id=”description”>就是</div><div>,所以我们可以采用变通法达到获取属性标签内容的目的。</p> <p></p> <p><span>复制代码</span> 代码如下:</p> <p><br> preg_match('/<(div)[^c]*class=\"attributes\"[^>]*>.*<\/\\1>/is', $text, $text0);<br> //这个正则会抓取<div开始到整个页面最后一个</div>标签,当然我们属性标签就在这个的前面部分。<br>  <br> $text1=preg_replace("/<\/div>[^<]*<(div)[^c]*id=\"description\"[^>]*>.*<\/\\1>/is","",$text0);<br> //匹配到</div ><div id=”description”>至最后</div>然后用””代替(就是把匹配的删除了),所以如果attributes的div后面紧跟的是description那么我们已经达到目的了。<br>  <br> $attributes=preg_replace("/</div>[^<]*<(div)[^c]*class="box J_TBox"[^>]*>.*</\1>/is","",$text1);<br> //如果attributes后面紧跟box J_Tbox标签,那么我们还需要使用以上这步来剔除box J_Tbox标签,当然如果attributes的div后面紧跟的是description,这一步将不会匹配到任何即什么都不会做。<br> </p> <p>E.获取描述:</p> <p>通过上面方法你肯定觉得淘宝页面上任何标签都可以很简单获取了吧(我之前也是这么想的),但是使用这个方法获取描述时得到的内容将会是“描述加载中”,是的,这个描述内容不是在源码中的,它是打开页面加载进一大堆js后,,不知道从淘宝的哪个角落中加载进来的。</p> <p>好吧,那么我们也可以模仿它放一些js进去。不知道哪些对加载描述有用?没事,全加载进来肯定没错。不知道需要放那些特定div上去有作用?抓一个源码,删掉一些div一步步试试看,你会发现“<div id=”detail”> </div></p> <p></p> <p><span>复制代码</span> 代码如下:</p> <p><br> <div><br>  <br> <div>描述加载中</div><br>  <br> </div><br> </p> <p>这几个div是加载描述所必须的,那么下面就是写代码了:</p> <p></p> <p><span>复制代码</span> 代码如下:</p> <p><br> preg_match_all('/<script[^>]*>[^<]*</script>/is', $text, $content);//页面js脚本<br>  $content=$content[0];<br>  $description='<div> </div><br>   <div><br>    <div>描述加载中</div><br>   </div>';<br> foreach ($content as &$v){$description.=iconv('GBK','UTF-8',$v);};<br> //将这个$description放进页面,描述就会自动的加载进来了,当然多个商品描述在同一个页面也会只有一个描述会被加载的。<br> </p> </div> </div> <div class="wzconShengming_sp"> <div class="bzsmdiv_sp">本站声明</div> <div>本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系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>热门文章</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796780570.html" title="R.E.P.O.能量晶体解释及其做什么(黄色晶体)" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.能量晶体解释及其做什么(黄色晶体)</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>2 周前</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796773439.html" title="仓库:如何复兴队友" class="phpgenera_Details_mainR4_bottom_title">仓库:如何复兴队友</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 周前</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796774171.html" title="Hello Kitty Island冒险:如何获得巨型种子" class="phpgenera_Details_mainR4_bottom_title">Hello Kitty Island冒险:如何获得巨型种子</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796775427.html" title="击败分裂小说需要多长时间?" class="phpgenera_Details_mainR4_bottom_title">击败分裂小说需要多长时间?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By DDD</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796775336.html" title="R.E.P.O.保存文件位置:在哪里以及如何保护它?" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.保存文件位置:在哪里以及如何保护它?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By DDD</span> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/zh/article.html">显示更多</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>热AI工具</h2> </div> <div class="phpgenera_Details_mainR3_bottom"> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title"> <h3>Undresser.AI Undress</h3> </a> <p>人工智能驱动的应用程序,用于创建逼真的裸体照片</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title"> <h3>AI Clothes Remover</h3> </a> <p>用于从照片中去除衣服的在线人工智能工具。</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title"> <h3>Undress AI Tool</h3> </a> <p>免费脱衣服图片</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title"> <h3>Clothoff.io</h3> </a> <p>AI脱衣机</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/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/zh/ai/ai-hentai-generator" title="AI Hentai Generator" class="phpmain_tab2_mids_title"> <h3>AI Hentai Generator</h3> </a> <p>免费生成ai无尽的。</p> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/zh/ai">显示更多</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>热门文章</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796780570.html" title="R.E.P.O.能量晶体解释及其做什么(黄色晶体)" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.能量晶体解释及其做什么(黄色晶体)</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>2 周前</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796773439.html" title="仓库:如何复兴队友" class="phpgenera_Details_mainR4_bottom_title">仓库:如何复兴队友</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 周前</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796774171.html" title="Hello Kitty Island冒险:如何获得巨型种子" class="phpgenera_Details_mainR4_bottom_title">Hello Kitty Island冒险:如何获得巨型种子</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By 尊渡假赌尊渡假赌尊渡假赌</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796775427.html" title="击败分裂小说需要多长时间?" class="phpgenera_Details_mainR4_bottom_title">击败分裂小说需要多长时间?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By DDD</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/1796775336.html" title="R.E.P.O.保存文件位置:在哪里以及如何保护它?" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.保存文件位置:在哪里以及如何保护它?</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By DDD</span> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/zh/article.html">显示更多</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>热工具</h2> </div> <div class="phpgenera_Details_mainR3_bottom"> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/toolset/development-tools/92" title="记事本++7.3.1" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="记事本++7.3.1" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/toolset/development-tools/92" title="记事本++7.3.1" class="phpmain_tab2_mids_title"> <h3>记事本++7.3.1</h3> </a> <p>好用且免费的代码编辑器</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/toolset/development-tools/93" title="SublimeText3汉化版" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3汉化版" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/toolset/development-tools/93" title="SublimeText3汉化版" class="phpmain_tab2_mids_title"> <h3>SublimeText3汉化版</h3> </a> <p>中文版,非常好用</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/toolset/development-tools/121" title="禅工作室 13.0.1" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="禅工作室 13.0.1" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/toolset/development-tools/121" title="禅工作室 13.0.1" class="phpmain_tab2_mids_title"> <h3>禅工作室 13.0.1</h3> </a> <p>功能强大的PHP集成开发环境</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title"> <h3>Dreamweaver CS6</h3> </a> <p>视觉化网页开发工具</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="https://www.php.cn/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Mac版" /> </a> <div class="phpmain_tab2_mids_info"> <a href="https://www.php.cn/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Mac版</h3> </a> <p>神级代码编辑软件(SublimeText3)</p> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="https://www.php.cn/zh/ai">显示更多</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>热门话题</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="https://www.php.cn/zh/faq/gmailyxdlrkzn" title="gmail邮箱登陆入口在哪里" class="phpgenera_Details_mainR4_bottom_title">gmail邮箱登陆入口在哪里</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/zh/faq/java-tutorial" title="Java教程" class="phpgenera_Details_mainR4_bottom_title">Java教程</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/zh/faq/cakephp-tutor" title="CakePHP 教程" class="phpgenera_Details_mainR4_bottom_title">CakePHP 教程</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/zh/faq/laravel-tutori" title="Laravel 教程" class="phpgenera_Details_mainR4_bottom_title">Laravel 教程</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/zh/faq/php-tutorial" title="PHP教程" class="phpgenera_Details_mainR4_bottom_title">PHP教程</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/zh/faq/zt">显示更多</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/zh/faq/1796604977.html" title="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/2024091017250464952.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP 项目配置" /> </a> <a href="https://www.php.cn/zh/faq/1796604977.html" title="CakePHP 项目配置" class="phphistorical_Version2_mids_title">CakePHP 项目配置</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:25 PM</span> <p class="Articlelist_txts_p">在本章中,我们将了解CakePHP中的环境变量、常规配置、数据库配置和电子邮件配置。</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796733273.html" title="适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南" 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="适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南" /> </a> <a href="https://www.php.cn/zh/faq/1796733273.html" title="适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南" class="phphistorical_Version2_mids_title">适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南</a> <span class="Articlelist_txts_time">Dec 24, 2024 pm 04:42 PM</span> <p class="Articlelist_txts_p">PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796604998.html" title="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/000/887/227/172596042710877.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP 日期和时间" /> </a> <a href="https://www.php.cn/zh/faq/1796604998.html" title="CakePHP 日期和时间" class="phphistorical_Version2_mids_title">CakePHP 日期和时间</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:27 PM</span> <p class="Articlelist_txts_p">为了在 cakephp4 中处理日期和时间,我们将使用可用的 FrozenTime 类。</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796604999.html" title="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/000/000/164/172596043255110.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP 文件上传" /> </a> <a href="https://www.php.cn/zh/faq/1796604999.html" title="CakePHP 文件上传" class="phphistorical_Version2_mids_title">CakePHP 文件上传</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:27 PM</span> <p class="Articlelist_txts_p">为了进行文件上传,我们将使用表单助手。这是文件上传的示例。</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796604978.html" title="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/000/465/014/172596030742788.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP 路由" /> </a> <a href="https://www.php.cn/zh/faq/1796604978.html" title="CakePHP 路由" class="phphistorical_Version2_mids_title">CakePHP 路由</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:25 PM</span> <p class="Articlelist_txts_p">在本章中,我们将学习以下与路由相关的主题?</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796605002.html" title="讨论 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="讨论 CakePHP" /> </a> <a href="https://www.php.cn/zh/faq/1796605002.html" title="讨论 CakePHP" class="phphistorical_Version2_mids_title">讨论 CakePHP</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:28 PM</span> <p class="Articlelist_txts_p">CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796728164.html" title="如何设置 Visual Studio Code (VS Code) 进行 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/000/000/080/6764e39e44ffe544.png?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何设置 Visual Studio Code (VS Code) 进行 PHP 开发" /> </a> <a href="https://www.php.cn/zh/faq/1796728164.html" title="如何设置 Visual Studio Code (VS Code) 进行 PHP 开发" class="phphistorical_Version2_mids_title">如何设置 Visual Studio Code (VS Code) 进行 PHP 开发</a> <span class="Articlelist_txts_time">Dec 20, 2024 am 11:31 AM</span> <p class="Articlelist_txts_p">Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写</p> </div> <div class="phphistorical_Version2_mids"> <a href="https://www.php.cn/zh/faq/1796604997.html" title="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/000/000/164/172596041825531.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="CakePHP 创建验证器" /> </a> <a href="https://www.php.cn/zh/faq/1796604997.html" title="CakePHP 创建验证器" class="phphistorical_Version2_mids_title">CakePHP 创建验证器</a> <span class="Articlelist_txts_time">Sep 10, 2024 pm 05:26 PM</span> <p class="Articlelist_txts_p">可以通过在控制器中添加以下两行来创建验证器。</p> </div> </div> <a href="https://www.php.cn/zh/php-tutorials.html" 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>公益在线PHP培训,帮助PHP学习者快速成长!</p> </div> <div class="footermid"> <a href="https://www.php.cn/zh/about/us.html">关于我们</a> <a href="https://www.php.cn/zh/about/disclaimer.html">免责声明</a> <a href="https://www.php.cn/zh/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?1743506431"></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>