求大神支招,php怎么操作在一個(gè)html文件的<head>標(biāo)記內(nèi)添加內(nèi)容?
問(wèn)題描述
// 追加內(nèi)容 $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);
現(xiàn)在上述代碼是在html的第一行加了<link type="text/css" rel="stylesheet" href="/css/hover.css" />,請(qǐng)問(wèn),如果</head>結(jié)尾的前面追加<link type="text/css" rel="stylesheet" href="/css/hover.css" />怎么實(shí)現(xiàn)呢?謝謝
問(wèn)題解答
回答1:把html文件后綴改成.php,直接在頁(yè)面所需要的位置上添加原來(lái)php代碼就行了
相關(guān)文章:

網(wǎng)公網(wǎng)安備