Home > Enterprise >  How would I be able to set the pages title as content from a text file?
How would I be able to set the pages title as content from a text file?

Time:02-21

I have a page that needs a dynamically updated title. I have a .txt file that is dynamically updated by another script on my website, and I would like to set the content of that file as the page title (the <title> tag). Can somebody help me?

CodePudding user response:

follow the below example, I am not tested it but try it once

<?php
   $data = fopen("c:\\folder\\testing.txt", "r");
   $ln_array = [];
   $fp = fopen("testfile.txt", "r");
   while (!feof($fp)) {
       // do stuff to the current line here
       array_push($ln_array, $fp);
   }
   fclose($fp);

?>

CodePudding user response:

In PHP, you can read the txt file and make à echo later

<?php
  $myfile = fopen("file.txt", "r") or die("Unable to open file!");
  $content = fgets($myfile);
  fclose($myfile);
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo($content); ?></title>
</head>
<body>
    
</body>
</html>
  • Related