搜索

首页  >  问答  >  正文

求大神支招,php怎么操作在一个html文件的<head>标记内添加内容?

    // 追加内容
    $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" />怎么实现呢?谢谢

人生若只是初见人生若只是初见1889 天前1084

全部回复(1)我来回复

  • 殘留の回憶

    殘留の回憶2019-12-05 18:58:12

    把html文件后缀改成.php,直接在页面所需要的位置上添加原来php代码就行了

    回复
    0
  • 取消回复