文章详情页
求大神支招,php怎么操作在一个html文件的<head>标记内添加内容?
浏览:192日期: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
相关文章:
排行榜
![$fields = $values = [];这条代码一直定义不了,一直报错,老师的源码也是被报错的,执行不了,请问该怎么解决这个问题](http://www.haobala.com/attached/image/news/202205/093622cb60.png)