您的位置:首頁/技術文章
文章詳情頁

求大神支招,php怎么操作在一個html文件的<head>標記內添加內容?

瀏覽:120日期:2022-06-07 11:53:37

問題描述

// 追加內容 $file = fopen(dirname(dirname(__FILE__)).'/index.htm', 'r'); $content = fread($file, filesize(dirname(dirname(__FILE__)).'/index.htm'));$hello = '<link type="text/css" rel="stylesheet" href="/css/hover.css" />' . PHP_EOL . $content; fclose($file); $file = fopen(dirname(dirname(__FILE__)).'/index.htm', 'w'); echo fwrite($file, $hello); fclose($file);

現在上述代碼是在html的第一行加了<link type="text/css" rel="stylesheet" href="/css/hover.css" />,請問,如果</head>結尾的前面追加<link type="text/css" rel="stylesheet" href="/css/hover.css" />怎么實現呢?謝謝

問題解答

回答1:

把html文件后綴改成.php,直接在頁面所需要的位置上添加原來php代碼就行了

標簽: HTML
相關文章:
国产综合久久一区二区三区