導航:首頁 > 編程語言 > phpshtml

phpshtml

發布時間:2025-06-04 05:23:52

『壹』 怎麼讓html識別php代碼

利用php解析html沒有現成的方法,需要利用第三方插件PHP Simple HTML DOM Parser,它可以以類似jQuery的方式通過css選擇器來返回指定的DOM元素,功能十分強大。
1、首先要在程序的開始引入simple_html_dom.php這個文件
參考代碼:include_once('simple_html_dom.php');
2、PHP Simple HTML DOM Parser提供了3種方式來創建DOM對象
參考代碼如下:
// Create a DOM object from a string
$html = str_get_html('<html><body>Hello!</body></html>');
// Create a DOM object from a URL
$html = file_get_html('');
// Create a DOM object from a HTML file
$html = file_get_html('test.htm');
得到DOM對象後就可以進行各種操作了
// Find all anchors, returns a array of element objects
$ret = $html->find('a');
// Find (N)th anchor, returns element object or null if not found (zero based)
$ret = $html->find('a', 0);
// Find lastest anchor, returns element object or null if not found (zero based)
$ret = $html->find('a', -1);
// Find all <div> with the id attribute
$ret = $html->find('div[id]');
// Find all <div> which attribute id=foo
$ret = $html->find('div[id=foo]');

閱讀全文

與phpshtml相關的資料

熱點內容
人工智慧演算法是多少位進制 瀏覽:920
發出命令的人 瀏覽:515
androidmainxml 瀏覽:109
des可逆加密演算法 瀏覽:249
aix查看系統信息常用命令 瀏覽:154
phpmemcache實例 瀏覽:249
爆槍源碼 瀏覽:567
編程大佬能記住所有代碼 瀏覽:859
如何批量注冊國家反詐app 瀏覽:527
實現ping命令 瀏覽:19
cmd進入管理員命令 瀏覽:479
pdf在線編輯修改 瀏覽:967
文件夾是只讀是什麼意思 瀏覽:88
伺服器如何知道訪問域名 瀏覽:319
java網路編程實驗總結 瀏覽:86
linux下dns伺服器配置 瀏覽:707
我的命令是絕對的 瀏覽:932
助飛器app在哪裡下 瀏覽:64
無廣告win10解壓縮 瀏覽:476
台灣的伺服器怎麼選雲伺服器 瀏覽:813